Hdu2041 超级楼梯 (斐波那契数列)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041

超级楼梯

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 86599    Accepted Submission(s): 44398


Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
 
Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
 
Output
对于每个测试实例,请输出不同走法的数量
 
Sample Input
2 2 3
 
Sample Output
1 2
 
 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 int a[50];
 5 int n,x;
 6 void init()
 7 {
 8     a[0]=0,a[1]=1,a[2]=1;
 9     for(int i=3;i<50;i++){
10         a[i]=a[i-1]+a[i-2];
11     }
12 }
13 int main()
14 {
15     init();
16     while(cin>>n){
17         while(n--){
18             cin>>x;
19             cout<<a[x]<<endl;
20         }
21     }
22     return 0;
23 }

猜你喜欢

转载自www.cnblogs.com/shixinzei/p/10678619.html