BC166 小乐乐走台阶
思路:
step1:如果剩下1步或者0步,返回1;否则,返回fn(n-1)和fn(n-2);
代码如下:
def fn(n):
if n == 0 or n == 1:
return 1
return fn(n-1) + fn(n-2)
n = int(input())
print(fn(n))
def fn(n):
if n == 0 or n == 1:
return 1
return fn(n-1) + fn(n-2)
n = int(input())
print(fn(n))