# 通常模式,
def fn1(n):
if n <= 1:
return n
else:
return fn(n-1) + fn(n-2)
# 优化算法:
def fn2(n):
if n <=1:
return (n,0)
else:
(a,b) = fn2(n-1)
return (a+b,a)
# 通常模式,
def fn1(n):
if n <= 1:
return n
else:
return fn(n-1) + fn(n-2)
# 优化算法:
def fn2(n):
if n <=1:
return (n,0)
else:
(a,b) = fn2(n-1)
return (a+b,a)
本文标题:递归求斐波那契数优化
本文链接:https://www.haomeiwen.com/subject/bbnpzftx.html
网友评论