題目描述:
有一樓梯共M級,剛開始時你在第一級,若每次只能跨上一級或二級,要走上第M級,共有多少種走法?
輸入描述:
輸入數據首先包含一個整數N,表示測試實例的個數,然後是N行數據,每行包含一個整數M(1<=M<=40),表示樓梯的級數。
輸出描述:
對於每個測試實例,請輸出不同走法的數量
輸入:
2
2
3
輸出:
1
2
題意:
字面意思
題解:
斐波拉切數列
代碼:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 50;
ll f[maxn];
void init(){
f[1] = 1;
f[2] = 1;
for(int i = 3; i <= 40; i ++){
f[i] = f[i - 1] + f[i - 2];
}
}
int main(){
init();
int n,t;
scanf("%d",&t);
while(t --){
scanf("%d",&n);
printf("%lld\n",f[n]);
}
return 0;
}