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

Constraints

Example

Input
n = 5
Output
8

Solve it

More in 1-D DP

All algorithm problems