dp
of size n + 1
to store the number of ways to reach each step.dp[0]
to 1 and dp[1]
to 1, since there is only one way to reach the first step (either step 0 or step 1).n
, and for each i
, set dp[i]
to dp[i-1] + dp[i-2]
.dp[n]
will be the answer, which is the number of distinct ways to climb to the top.