Go To Goal
Time limit1sMemory limit512 MB
Count the sequences of N two-step and M one-step moves totaling 2N+M that never place three two-step moves in consecutive turns, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math, Greedy
- Solved
- No attempts yet
Problem
Ani is playing a game with one piece and squares, numbered from to . The piece starts on square . Ani also has super cards and normal cards.
On each turn, Ani can use one of her unused cards. If she uses a normal card, the piece moves one square ahead, from square to square . If she uses a super card, the piece moves two squares ahead, from square to square . Ani cannot use super cards too often: she cannot use three super cards in three consecutive turns.
After turns, the piece must be on square , the goal. Ani wants to know the number of paths her piece can take to the goal. Two paths are different if the piece is on different squares after the same number of turns.
For example, if and , there are two paths the piece can take to the goal:
- Use the normal card on the second turn, and the super cards on the first, third, and fourth turns.
- Use the normal card on the third turn, and the super cards on the first, second, and fourth turns.
Ani cannot use the normal card on the first turn, because then she would have to use the super cards on the last three turns in a row.
Input
The input begins with a line containing two integers (), the number of super cards and normal cards.
Output
Output one line with the number of paths the piece can take to the goal. The answer can be large, so output it modulo .