Changho's Preparation for Study Abroad
Time limit2sMemory limit1024 MB
Count the study sequences of length N over X words where each of the Y well-known words never repeats Z or more times in a row, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Matrix
- Solved
- No attempts yet
문제
Changho is preparing to study abroad and has been focusing on foreign language study lately. Jaewoo wanted to help, so he gave Changho a list of distinct foreign words. However, of the words on the list were already well known to Changho. Changho calls these words Well-Known words. To study efficiently, Changho set his own rule: for Well-Known words, he will not study the same word or more times in a row. After hearing this rule, Jaewoo became curious about the total number of ways Changho can study the words on the list.
Each study session covers exactly one word. Given the number of study sessions , the number of words on the list, the number of Well-Known words , and the limit , find the total number of ways Changho can study the words on the list. The same word may be studied many times, and some words may never be studied.
입력
The first line contains four integers (), (), (), and (), separated by spaces.
출력
Print the total number of ways Changho can study the words on the list, modulo , because the answer can be large.