Staircase Problem
Let's solve the Staircase problem using Dynamic Programming.
Statement
A child is running up a staircase with n
steps and can hop either 1 step, 2 steps, or 3 steps at a time. Your task is to count the number of possible ways that the child can climb up the stairs.
Let’s say the child has to climb three stairs. There are four ways to do it.
- Three consecutive hops of step each:
- One hop of step and one hop of steps:
- One hop of steps and one hop of step:
- One hop of steps:
To clarify the basis of the calculation, we define these rules:
- If , we are already at the top of the stairs, and need to take steps. We will define this as way.
- If , we can take
Access this course and 1400+ top-rated courses and projects.