openjudge-NOI 2.6-1944 吃糖果
题目链接:http://noi.openjudge.cn/ch0206/1944/
题解:
递推,题目中给出了很详细的过程,不讲解
1 #include<cstdio> 2 int n; 3 int work(int x) 4 { 5 if(x==1)return 1; 6 if(x==2)return 2; 7 return work(x-1)+work(x-2); 8 } 9 int main() 10 { 11 scanf("%d",&n); 12 printf("%d",work(n)); 13 return 0; 14 }
其实我还爱着打表~
1 #include<cstdio> 2 int f[]={0,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946}; 3 int main() 4 { 5 int n; 6 scanf("%d",&n); 7 printf("%d",f[n]); 8 return 0; 9 }