杭电1715--大菲波数

大菲波数

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14085    Accepted Submission(s): 4795


Problem Description
Fibonacci数列,定义如下:
f(1)=f(2)=1
f(n)=f(n-1)+f(n-2) n>=3。
计算第n项Fibonacci数值。
 

 

Input
输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。
 

 

Output
输出为N行,每行为对应的f(Pi)。
 

 

Sample Input
5
1
2
3
4
5
 

 

Sample Output
1
1
2
3
5
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1753 1063 1133 1250 2100 
 
 1 #include <stdio.h>
 2 #include <string.h>
 3 int fei[1010][1010];
 4 int main()
 5 {
 6     int i, j;
 7     int temp, plus = 0;
 8     memset(fei, 0, sizeof(fei));
 9     fei[1][0] = 1;
10     fei[2][0] = 1;
11     for(i=3; i<1010; i++)
12     {
13         for(j=0; j<1010; j++)
14         {
15             temp = fei[i-1][j] + fei[i-2][j] + plus;   //
16             fei[i][j] = temp%10;
17             plus = temp/10;        
18         }
19     }
20     int n, m;
21     scanf("%d", &n);
22     while(n--)
23     {
24         scanf("%d", &m);
25         for(i=1009; i>=0; i--)
26         if(fei[m][i])
27         break;
28         for(;i>=0 ;i--)
29         printf("%d",fei[m][i]);
30         printf("
");
31     }
32     return 0;    
33 } 
原文地址:https://www.cnblogs.com/soTired/p/4676408.html