A stable tower of height n is a tower consisting of exactly n tiles of the same height, laid vertically in such a way that a larger tile does not lie on a smaller tile. Example:
[ one ]
[2]
[3]
[ four ]
We have an infinite number of tiles of sizes 1, 2, ..., m. The task is to calculate the number of possible stable towers of height n that can be built from these tiles, taking into account the fact that you can use no more than k tiles of each size in the tower.
Note: two towers of height n are different only when there is such a height h (1 <= h <= n) that the towers have tiles of different sizes at height h.
Examples:
Input: n = 3, m = 3, k = 1.
Output: 1
Possible sequence: {1, 2, 3}. The answer is 1.
Input: n = 3, m = 3, k = 2.
Output: 7
{1, 1, 2}, {1, 1, 3}, {1, 2, 2}, {1, 2, 3}, {1, 3, 3}, {2, 2, 3}, {2 , 3, 3}.