#P5004. Jumping Across Grids
Jumping Across Grids
Jumping Across Grids
You are given N cells arranged in a row and numbered from 1 to N. You stand on the far left of cell 1 (i.e. infinitely far to its left) and you want to jump until you reach a position to the right of cell N. However, every time you jump from one cell to another, the cells in between (i.e. the gap) must contain at least M cells that you do not step on. Note that the jump from your starting position (which is not a cell) to the first cell you touch and the final jump from your last touched cell to the finish (which is not a cell) do have restrictions as well:
- For the first jump, if you land on cell a, then there are exactly a − 1 cells between the start and cell a. Thus you must have a − 1 \ge M, i.e. a \ge M+1.
- For any jump from cell a to cell b (with a < b), the gap contains b − a − 1 cells, so you need b − a − 1 \ge M (or b \ge a+M+1).
- For the final jump from your last touched cell a to the finish (to the right of cell N), the gap contains N − a cells. Hence you must have N − a \ge M (or a \le N−M).
A path is defined by the sequence of cells you step on along the way. Two paths are considered different if and only if there is a cell that is visited in one path but not the other. Note that it is allowed to not step on any cell at all (i.e. making one giant jump directly from the start to the finish) if the conditions allow it.
Your task is to compute the number of different paths you can take, modulo \(10^9+7\).
Input/Output note: You will be given N and M on a single line, and you should output the number of valid paths modulo \(10^9+7\). If no valid path exists, output 0.
inputFormat
The input consists of one line containing two integers N and M separated by a space.
Constraints: It is guaranteed that N and M are non‐negative integers. Note that a valid jump from the start to the finish is possible only if N \ge M.
outputFormat
Output one integer: the number of valid paths modulo \(10^9+7\).
sample
5 1
5