请问计算出你可以采用多少种不同的方式爬完这个楼梯(到最后一层为爬完)。
(注意超大数据)
import sys def diffroad(n): # n<3 索引位置:n-1 # n>=3 索引位置:(n-1)%3 res = [1,1,2] if n<3: return 1 if n==3: return 2 # f(n) = f(n-1)+f(n-3) for i in range(4,n+1): res[(i-1)%3] += res[(i+1)%3] return res[(n-1)%3] if __name__=="__main__": n = int(sys.stdin.readline().strip()) print(diffroad(n))
import sys try: while True: line = sys.stdin.readline().strip() if line == '': break n=int(line) if 100<=n<500: sum=0 for i in range(1,n//3): res=1 for j in range(2*i,3*i): res*=(n-j) for k in range(1,i+1): res//=k sum+=res if n%3==0: sum+=2 elif n%3==1: sum+=n//3+2 else: res=1 for i in range(1,n//3+1): res=res*(n//3+3-i)//i sum+=res+1 print(sum) except: pass
line = input() if line == '': print(None) n = int(line) if 100 <= n < 500: a = [1, 1, 2] for _ in range(n-3): a = [a[1], a[2], a[0] + a[2]] print(a[2])