标签:
这题纯暴力会超时,只需简单推一下递推公式即可,其实就是一个斐波拉契数列。
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 15937 | Accepted: 7861 |
Description
Input
Output
Sample Input
2 3 1
Sample Output
Scenario #1: 5 Scenario #2: 2
Source
1 //oimonster 2 #include<cstdio> 3 #include<cstdlib> 4 #include<iostream> 5 using namespace std; 6 int a[101]; 7 int main(){ 8 int i,j,n,k; 9 scanf("%d",&n); 10 a[0]=0; 11 a[1]=2; 12 a[2]=3; 13 for(i=3;i<=45;i++){ 14 a[i]=a[i-1]+a[i-2]; 15 } 16 for(i=1;i<=n;i++){ 17 scanf("%d",&k); 18 printf("Scenario #%d:\n",i); 19 printf("%d\n",a[k]); 20 printf("\n"); 21 } 22 return 0; 23 }
标签:
原文地址:http://www.cnblogs.com/oimonster/p/4298913.html