标签:style blog color io div log sp amp c
NYOJ (01串)
我非要用递归,我非要用记忆化搜索
1 #include<stdio.h> 2 #include<string.h> 3 4 int N; 5 int a[100][2]; 6 7 int solve(int i, int tem) 8 { 9 if(i==N) 10 { 11 if(tem==0) 12 return 2; 13 else 14 return 1; 15 } 16 if(a[i][tem]>=0) 17 return a[i][tem]; 18 if(tem==0) 19 return a[i][tem]=solve(i+1,0)+solve(i+1,1); 20 else 21 return a[i][tem]=solve(i+1,0); 22 } 23 24 int main() 25 { 26 int T; 27 scanf("%d",&T); 28 while(T--) 29 { 30 memset(a,-1,sizeof(a)); 31 scanf("%d",&N); 32 printf("%d\n",solve(1,0)); 33 } 34 return 0; 35 }
尼玛,自己就是一逗比!!
标签:style blog color io div log sp amp c
原文地址:http://www.cnblogs.com/chaiwentao/p/3948108.html