python如何計(jì)算斐波那契函數(shù)的運(yùn)算時(shí)間以及計(jì)算結(jié)果?
def Fibonacci(n):
if n == 1:
return 1
dic = [-1 for i in xrange(n)]
dic[0], dic[1] = 1, 1
helper(n-1, dic)
linesize = 5
file=open('Fibonacci.txt', 'w')
for loop in range(len(dic)/linesize):
line = []
for i in range(linesize):
line.append(dic[i + linesize * loop])
file.write("\t".join([str(x) for x in line]) + "\n")
file.close()
def helper(n, dic):
if dic[n] < 0:
dic[n] = helper(n-1, dic)+helper(n-2, dic)
return dic[n]
上一篇書柜無背板怎么安背板
下一篇lcb幫正常燈亮不起來