ブロックの構成を数える問題

最近TopCoderの数学とアルゴリズムに関わる問題を解くようにしています。ジャンルは組み合わせ数学と幾何学です。
Basically, the problem is, given w and h, to count the number of block structures which can be computed on a base of width w up to a height h (not counting the base). The blocks which can be used are 1x1x1, 1x1x2,1x1x3. The first 2 types can be stacked only atop another block, while the third can be stacked atop 2 blocks with an empty space between or 3 blocks. As the result can be large, the answer must be given mod 1000000007.
I was able to solve this problem in the limited cases of w element of [1,2] and h element of [1,3]. This was done as follows:
1. count 1 for just the base
2. using a recursiveSetBlocks method which takes an input structure, the current height, and the current column, try adding a 1x1x1,1x1x2,1x1x3 block. This basically performs a depth-first traversal of an n-ary tree of states.
3. For each addition, try recursively adding blocks above the addition and then to the right of the addition.
While this works in all of the small-scale problems above, it fails in a case as simple as w=3,h=2 (84 expected, 71 returned). This is because some simple cases of placing a 1x1x2 or 1x1x3 block above a partially completed row is not considered.
他人の正解解説によって以下の手法を使うべきです。Use recurrence F(h,prev) where h is the height, prev the previous row bitmap. This recurrence 回帰 will memoize the number of structures mod 100000007 in a 2-d array indexed by (h,prev). If h=0, 1 is returned (meaning the top row was set). The first call will be F(h,1<