1180: 零起点学算法87——超级楼梯(有疑问)

1180: 零起点学算法87——超级楼梯

Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 1803  Accepted: 431
[Submit][Status][Web Board]

Description

有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?

 

Input

输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。

 

Output

对于每个测试实例,请输出不同走法的数量。

 

Sample Input

 
2
2
3

 

Sample Output

1
2

 

Source

 
 1 #include<stdio.h>
 2 int main(){
 3     long long a[100];
 4     a[1]=1; a[2]=1; a[3]=2;
 5     for(int i=4;i<=40;i++){
 6         a[i]=a[i-1]+a[i-2];
 7     }
 8     long long n;
 9     scanf("%lld",&n);
10     while(n--){
11         int m;
12         scanf("%d",&m);
13         printf("%lld\n",a[m]);
14     }
15     return 0;
16 }

a[1]为什么是1??初始是第一级 还需要爬嘛??

posted @ 2017-04-11 00:29  Dollis  阅读(1269)  评论(0编辑  收藏  举报