pytnon 动态编程
我理解所谓动态编程或动态规划,就是保存上一步计算结果,用于下一步的计算,以减少递归调用次数。例如计算斐波那契函数:
#!/usr/bin/python # Write Python 3 code in this online editor and run it. def fib(n): m[0],m[1]=0,1 for i in range(2,n): m[i]=m[i-1]+m[i-2] return m #m =[0 for i in range(100)] m={} print(fib(110))