Crossing the stepping stones backward
Time limit2sMemory limit1024 MB
Count the self-avoiding paths from stone 1 to stone N when each move jumps forward by 1 to K or steps back by 1, modulo 1000000007.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Stones numbered through are placed in a row in order. Starting from stone , you move toward stone under the following rules.
- From stone , you can move to stone for an integer with .
- From stone , you can move to stone .
- You cannot move to a position where there is no stone.
- Including the start and the end, you cannot step on a stone you have already stepped on.
Find the number of ways to move from stone to stone under these rules, modulo . Two moves are different if the sequences of stone numbers stepped on are different.
Input
The first line contains the number of stones and the integer , separated by a space. (; )
Output
On the first line, print the number of ways to move from stone to stone under the rules, modulo .