I have been trying to understand the question extensively discussed here:
You have 4 types of lego blocks, of sizes 1 * 1 * 1, 1 * 1 * 2, 1 * 1 * 3 and 1 * 1 * 4. Assume you have infinite number of blocks of each type.
You want to make a wall of height H and width M out of these blocks. The wall should not have any holes in it. The wall you build should be one solid structure. A solid structure means that it should not be possible to separate the wall along any vertical line without cutting any lego block used to build the wall. The blocks can only be placed horizontally. In how many ways can the wall be built?
I think I understood most of the implementation of the algorithm except the following idea:
Branch on the leftmost place where the wall is not connected. The number of All W*H walls is the number of Solid X*H walls times the number of All {W-X}*H walls,
summed across all possible values of X, plus the number of Solid W*H walls:
Shouldn't the total # of possible W*H walls be the sum of the number of All W*H walls times the number of All {W-X}* walls plus the number of Solid W*H walls? (I think maybe there's double counting if we just take the sum of All W*H walls and the number of All {W-X}* walls though...)
This would ensure that there is one vertical break between X and W-X among other potential vertical breaks within {W-X}*H walls.
In contrast, the sum of the number of All W*H walls times the number of Solid X*H walls and the number of All {W-X}*H walls and the number of Solid W*H walls sounds much more restrictive as we are ensuring that there is no vertical break within Solid X*H walls.
I think my confusion may stem from the fact that I have a hard time wrapping my head around the way they count the number of cases based on the idea of Branch on the leftmost place where the wall is not connected. in order to arrive at the formula S(H,W) = A(H,W) - Sum(S(H, L) * A(H, W-L)) [L=1..W-1] (That the number of solid walls with no vertical breaks is the number of all possible cases minus the number of Solid X*H walls times the number of All {W-X}*H walls summed across all possible X values.