题解 | #跳台阶#
跳台阶
https://www.nowcoder.com/practice/bfb2a2b3cdbd4bd6bba0d4dca69aa3f0
def climb_stair(n): # 两种情况 if n > 1: dp = [0]*int(n+1) dp[1] = 1 dp[0] = 1 for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] else: return 1 while True: try: n = int(input()) print(climb_stair(n)) except: break
当前楼梯的方法,由前一个楼梯状态与前两阶楼梯的状态推导出来