标签:style blog http color ar 使用 sp div on
记忆化搜索是用来处理递归中的重复计算问题,不要小看这个问题,因为这个问题可能把你的程序的性能拉下谷底,复杂度可以达到$$O(2^N)$$。
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
实现1:
int f1(int x) {timer1++;return (x ==0||x==1) ? 1 : f1(x-1)+f1(x-2);}
实现2:
int dp[50];
int f(int x) {
shen++;
if(x == 0 || x == 1 ){ dp[0] = 1;dp[1] = 1; return 1;}
if(dp[x] != -1) return dp[x];
return dp[x]= f(x - 2)+f( x - 1);
}
标签:style blog http color ar 使用 sp div on
原文地址:http://www.cnblogs.com/shenyanqi/p/4049226.html