Statistics

Problem Statement for "DiagonalColumn"

Problem Statement

There is a grid with H rows and W columns. All cells in the grid are initially white.

You may perform zero or more painting steps. Each step looks as follows:

  1. You select either any one column of the grid, or any one diagonal that goes down and to the right.
  2. You paint all its cells black.

The same cell can be painted multiple times. Once it's black, it remains black when you paint it again.

Two grids are different if one of them has a white cell at some coordinates at which the other grid has a black cell. Compute and return the number of different grids you can obtain, modulo 1,000,000,007.

Definition

Class:
DiagonalColumn
Method:
countGrids
Parameters:
int, int
Returns:
int
Method signature:
int countGrids(int H, int W)
(be sure your method is public)

Constraints

  • H and W will be between 1 and 38, inclusive.

Examples

  1. 2

    2

    Returns: 12

    In the figure below, the columns and diagonals you are allowed to paint are shown using asterisks. columns: diagonals: *. .* .. *. .* *. .* *. .* .. The 12 different grids that can be produced are shown below, using '.' for white and '#' for black. .. .. .# #. .. #. .. #. #. .# .# ## .# .# #. #. ## .# #. ## .# ## ## ## And the four grids that cannot be produced look as follows: #. .. ## .. .. .# .. ##

  2. 2

    3

    Returns: 37

  3. 3

    2

    Returns: 28

  4. 1

    5

    Returns: 32

    Each of the 2^5 black-and-white grids can be produced.

  5. 6

    1

    Returns: 64

  6. 38

    38

    Returns: 173889321

  7. 1

    1

    Returns: 2

  8. 1

    2

    Returns: 4

  9. 2

    1

    Returns: 4

  10. 1

    38

    Returns: 877905026

  11. 38

    1

    Returns: 877905026

  12. 1

    35

    Returns: 359738130

  13. 2

    4

    Returns: 114

  14. 5

    2

    Returns: 124

  15. 3

    3

    Returns: 97

  16. 7

    7

    Returns: 455383

  17. 8

    3

    Returns: 3817

  18. 4

    15

    Returns: 23475582

  19. 20

    7

    Returns: 819951426

  20. 1

    5

    Returns: 32

  21. 1

    12

    Returns: 4096

  22. 1

    21

    Returns: 2097152

  23. 2

    4

    Returns: 114

  24. 9

    38

    Returns: 842071268

  25. 10

    7

    Returns: 3719511

  26. 11

    9

    Returns: 119096740

  27. 11

    38

    Returns: 867883277

  28. 12

    20

    Returns: 848104343

  29. 14

    27

    Returns: 868261569

  30. 18

    25

    Returns: 105113581

  31. 20

    10

    Returns: 338245748

  32. 23

    22

    Returns: 97737204

  33. 25

    35

    Returns: 825569109

  34. 27

    38

    Returns: 664024083

  35. 28

    37

    Returns: 368521022

  36. 29

    2

    Returns: 147483630

  37. 30

    1

    Returns: 73741817

  38. 30

    11

    Returns: 604592928

  39. 30

    38

    Returns: 686026055

  40. 32

    4

    Returns: 108101312

  41. 32

    6

    Returns: 10144107

  42. 32

    15

    Returns: 200632290

  43. 32

    24

    Returns: 453202823

  44. 32

    38

    Returns: 455885098

  45. 33

    37

    Returns: 766433769

  46. 33

    38

    Returns: 967662257

  47. 34

    20

    Returns: 433610898

  48. 34

    36

    Returns: 260621441

  49. 34

    37

    Returns: 891986731

  50. 34

    38

    Returns: 909977075

  51. 35

    35

    Returns: 245969105

  52. 35

    36

    Returns: 376478799

  53. 35

    37

    Returns: 219074228

  54. 35

    38

    Returns: 30111373

  55. 36

    34

    Returns: 952378827

  56. 36

    35

    Returns: 972723436

  57. 36

    36

    Returns: 52399766

  58. 36

    37

    Returns: 522725515

  59. 36

    38

    Returns: 247302652

  60. 37

    33

    Returns: 205358595

  61. 37

    34

    Returns: 751435092

  62. 37

    35

    Returns: 426232084

  63. 37

    36

    Returns: 404241707

  64. 37

    37

    Returns: 748424347

  65. 37

    38

    Returns: 170589035

  66. 38

    30

    Returns: 274152123

  67. 38

    32

    Returns: 459360570

  68. 38

    33

    Returns: 116506807

  69. 38

    34

    Returns: 349547622

  70. 38

    35

    Returns: 333249387

  71. 38

    36

    Returns: 107925582

  72. 38

    37

    Returns: 199822004

  73. 38

    38

    Returns: 173889321

  74. 37

    29

    Returns: 971826486

  75. 25

    36

    Returns: 416841565

  76. 9

    10

    Returns: 118374176


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: