首先关于尾递归
递归:你先帮我把下面搞定,撇准好我再来
尾递归:我直接先上再说
用尾递归写费波纳茨数列
def Fibonacci(n, cur = 1, next = 1):
if n == 0:
return 0
if n == 1:
return cur
return Fibonacci(n-1, next, cur + next)
用快速幂+矩阵
动态规划
pass
首先关于尾递归
递归:你先帮我把下面搞定,撇准好我再来
尾递归:我直接先上再说
def Fibonacci(n, cur = 1, next = 1):
if n == 0:
return 0
if n == 1:
return cur
return Fibonacci(n-1, next, cur + next)
pass