Challenge description
Let's define an W
x H
grid as a two-dimensional array of length H
whose each subarray is of length W
. Example: a 2x3 grid (.
character used as a blank):
..
..
..
A unit is a single point of a grid. A block is either a single unit or a set of contiguous units (meaning each unit of a block has at least another one next to, above or below it). In the 10x10 grid below there are 4 blocks (units represented by X
's):
........X. ........1.
..X....... ..2.......
..X....... ..2.......
..X....... ..2.......
.......X.. .......3..
.......XX. .......33.
.......XX. .......33.
..X....... ..4.......
..XX..X... ..44..4...
...XXXX... ...4444...
Two blocks are distinct if either their positions in the grid or the number of blocks they consist of are different. In the 10x10 grid below there are 5 blocks (they're all 2x2 squares, but their positions are different, therefore they're distinct):
.......... ..........
.XX....XX. .11....22.
.XX....XX. .11....22.
.......... ..........
.......XX. .......33.
.......XX. .......33.
....XX.... ....44....
....XX.... ....44....
XX........ 55........
XX........ 55........
Given two integers W
and H
(W, H > 0)
, calculate the number of distinct blocks that can be constructed within a W
x H
grid.
Sample inputs / outputs
(1, 1) -> 1 | only a 1x1 block can be constructed
(1, 2) -> 3 | two 1x1 blocks, and one 1x2 block
(2, 2) -> 13
(3, 3) -> 218
(4, 4) -> 11506
Two blocks are distinct if both their positions in the grid and the number of blocks they consist of are different.
I think you mean aneither
/or
rather than aboth
/and
here. Else, the sentence doesn't match the example with the 5 2x2 blocks. Also, it would probably be a good thing if you explicitly stated that the blocks for counting aren't all placed on the grid at the same time. That's implied by your(1,2)
example, but not explicit. With that being the case, this is very similar to the recent count-the-rectangle challenges. \$\endgroup\$