Stamp Painting
Time limit2sMemory limit512 MB
Count the distinct colorings of an N-unit canvas obtainable by stamping K-wide colored stamps so every unit ends up painted, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Bessie has an unit long strip of canvas (), and she intends to paint it. She was unable to acquire any paint brushes. In their place she has rubber stamps of different colors (), each stamp units wide (). She wants to know exactly how many different paintings she could create by stamping her stamps on the canvas in some order.
To use a stamp, align it with exactly neighboring units of the canvas. The stamp cannot extend beyond the ends of the canvas, and it cannot cover a fraction of a unit. Once placed, the stamp paints the covered units with its color. Any given stamp may be used many times, once, or never at all. By the time Bessie is finished, every unit of the canvas must have been painted at least once.
Count the paintings Bessie could produce, modulo . Two paintings that look identical but were made by different sequences of stamping operations count as the same painting.
Input
The first and only line has three integers , , and , separated by spaces. It is guaranteed that .
Output
Print the number of possible paintings, modulo , on one line.
Hint
With , , and stamp colors A and B, the possible paintings are AAA, AAB, ABB, BAA, BBA, BBB, which is 6 of them.