HDU - 2041 超級樓梯
來源:程序員人生 發(fā)布時間:2016-12-03 10:26:45 閱讀次數(shù):2424次
題目:
Description
有1樓梯共M級,剛開始時你在第1級,若每次只能跨上1級或2級,要走上第M級,共有多少種走法?
Input
輸入數(shù)據(jù)首先包括1個整數(shù)N,表示測試實例的個數(shù),然后是N行數(shù)據(jù),每行包括1個整數(shù)M(1<=M<=40),表示樓梯的級數(shù)。
Output
對每一個測試實例,請輸出不同走法的數(shù)量
斐波那契
代碼:
#include<iostream>
#include<stdio.h>
using namespace std;
long long list[50];
int main()
{
list[1] = 1;
list[2] = 2;
for (int i = 3; i < 50; i++)list[i] = list[i - 1] + list[i - 2];
int n, a;
cin >> n;
while (n--)
{
cin >> a;
cout << list[a⑴] << endl;
}
return 0;
}
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈