Problem
A staircase has N steps. You start at the bottom (step 0).
Each move, you can climb 1 step or 2 steps.
In how many different ways can you reach step N?
Each move, you can climb 1 step or 2 steps.
In how many different ways can you reach step N?
š§ DP Concept
This is a Dynamic Programming problem. You need a dp table ā an array where
Use set dp[i] to store values and get dp[i] to read them back.
Base cases: dp[0] = 1 (one way to be at the bottom: do nothing), dp[1] = 1.
Recurrence: dp[i] = dp[iā1] + dp[iā2] (you arrived from one step below or two steps below).
dp[i] stores the number of ways to reach step i.Use set dp[i] to store values and get dp[i] to read them back.
Base cases: dp[0] = 1 (one way to be at the bottom: do nothing), dp[1] = 1.
Recurrence: dp[i] = dp[iā1] + dp[iā2] (you arrived from one step below or two steps below).
Input Variables (pre-loaded)
š” Drag N, set dp[i], and get dp[i] from the toolbox.
Your Output
Result
ā
Run your program to see the result.
Execution Log
Ready. Press ā¶ Run to start.
Expected Answer
Answer:
?
Hint
Step 0