School Canteen
Time limit5sMemory limit256 MB
Count length-n menus over k meals with no meal repeated l times in a row, modulo 4000000009.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Matrix, Combinatorics
- Solved
- No attempts yet
Problem
The cooks in a school canteen are always busy. They have to plan the menu for all days of the school year, and they can make only different meals.
The students are picky eaters. If the same meal is served on days in a row, the students rebel against the cooks.
A menu assigns one meal to each of the days, and two menus are different if any single day gets a different meal. Count the menus that avoid a rebellion.
Input
The first line contains three space separated integers , and . is the number of days (), is the impatience of the students, that is, how many repeats of a single meal in a row make them rebel (), and is the number of possible meals ().
Output
Print on a single line the number of menus that avoid a rebellion, modulo . For the only menu is the empty one, so the answer is .
Hint
For , and there are exactly 12 menus with the required property.
1 2 1
1 2 3
1 3 1
1 3 2
2 1 2
2 1 3
2 3 1
2 3 2
3 1 2
3 1 3
3 2 1
3 2 3