Problem Description
有一樓梯共M級,剛開始時你在第一級,若每次只能跨上一級或二級,要走上第M級,共有多少種走法?
Input
輸入數據首先包含一個整數N,表示測試實例的個數,然後是N行數據,每行包含一個整數M(1<=M<=40),表示樓梯的級數。
Output
對於每個測試實例,請輸出不同走法的數量
Sample Input
2
2
3
Sample Output
1
2
源代碼:
#include<stdio.h>
int main()
{
int n,m,i,a[43];
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
a[2]=1;a[3]=2;
for(i=4;i<=m;i++)
a[i]=a[i-1]+a[i-2];
printf("%d\n",a[m]);
}
return 0;
}