解题思路:

当前阶梯可以由前一级阶梯跳一级到达,也可由前两级阶梯跳两级到达。

完整代码:

n = int(input())

if n <= 2:
  print(n)
else:
  dp = [0 for i in range(n)]
  dp[0] = 1
  dp[1] = 2
  for i in range(2, n):
    dp[i] = dp[i - 1] + dp[i - 2]
  print(dp[-1])