Block Stacking
Time limit1sMemory limit32 MB
Count distinct front-view colorings of supported stacks of width W and height at most H built from unlimited blocks of widths 1 to K, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Yeonggeul plays with blocks. He owns kinds of blocks. Every block has height 1, and the widths are 1 through . Blocks of the same width always have the same color, but two blocks of different widths may still have the same color. Every kind is available without limit. For example, if and the three blocks have three different colors, he can use as many of the following three blocks as he wants.

Yeonggeul stacks these blocks on a floor block of width . A tall stack is awkward to play with, so he keeps the height at most . The picture below shows an example with .
A block must line up exactly with the cells, and no empty space may be left under a placed block. The left picture follows the rules and the right picture does not.

In the left picture every block follows the rules and the height is 4. In the right picture the leftmost red block does not line up with the cells. The middle of the blue block has empty space under it, and the rightmost red block also has empty space under it. The right picture is therefore not a correct stacking.
Count the stackings that follow the rules. Two stackings that show the same color in every cell when seen from the front count as one. Stacking nothing at all counts as one case.
Input
The first line has three integers separated by spaces: the number of block kinds (), the width of the floor block , and the largest allowed height ().
The second line has integers. The -th number () is the color of the block of width .
Output
Print the number of stackings that follow the rules, modulo 1,000,000,007.