I have a problem with blocks that are stacked on top of each other and stacks are positioned next to each other.
The number of stacks w
(width) and the number of blocks b
are variables.
The height of a stack is [0,4]. A block can only be positioned on the bottom of a stack or on top of another stack (i.e. we have to respect gravity). All blocks are unique, so vertical and horizontal ordering are important.
Here is a sample of three different layouts for (w,b) = (4,8)
6 6 6
3 3 3
7 8 8 7 8 5 2
5 4 1 2 1 4 5 2 1 7 4
--------- --------- ---------
I need to calculate the number of possible layouts.
I started by calculating the number of combinations of stack heights. E.g.:
- 4 4 0 0
- 4 3 1 0
- 4 2 2 0
- 4 2 1 1
- ...
However, I did not manage to generalize this. We are talking about permutations with variable repeatable items depending on the sum of items.
Maybe I have the wrong approach and we should only concentrate on distributing b
blocks in w
stacks. But how do I remove the invalid combinations that have blocks floating in the air?
Thank you for your help. :)
P.S. If you wish, you can make the height [0,h] a variable as well. Then we would have (w,h,b)