Climbing Stairs — 1-D DP
Count the step sequences that land exactly on a staircase top when each move climbs one or two stairs, reported modulo a large number.
1-D DP · Easy
The problem
A patient is doing a rehab staircase exercise and may take either one step or two at a time. The staircase has n steps and the patient starts at the bottom. Each move takes you up either 1 step or 2 steps. Count the different sequences of moves that bring the patient to exactly step n, and return that count modulo 1000000007.
The story
A physiotherapist sets a rehab exercise on a staircase: each move goes up either one step or two. The staircase has n steps, somewhere from 1 to 5000. How many different sequences of moves end exactly on the top step? The number gets enormous, so report it modulo 1,000,000,007.
What to return
- Return the number of distinct move sequences, taken modulo 1000000007.
- Two sequences differ if at some move one takes 1 step and the other takes 2.
Constraints
- 1 <= n <= 5000
- Your code may run at most 59,992 counted steps on the largest case.
Example
- Input
n = 5- Output
8