題目描述:
小明在坐景馳科技研發的無人車到達了目的地。
景馳科技(JingChi.ai)是一家由人工智能技術驅動、以無人駕駛技術爲核心的智能出行公司。它將打造面向中國市場的全無人駕駛。
從無人車下來以後,小明看到了一個長長的樓梯。
有一個n級臺階的樓梯,小明一次可以向上跳1步,兩步,甚至是n步,請問小明跳到n級臺階有多少種跳法?
輸入描述:
第一行輸入一個整數t,代表有t組樣例:( T<=30)
接下來的t行,都用一個整數n,表示樓梯有n級臺階( 1<=n<=30)
輸出描述:
輸出跳到第n級臺階有多少種跳法
輸入:
1
1
輸出:
1
題意:
題目描述
題解:
寫出來遞推就好了
代碼:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 35;
ll f[maxn];
void init(){
f[1] = 1;
f[2] = 2;
f[3] = 4;
for(int i = 4; i <= 30; i ++){
f[i] = 2 * f[i - 1] ;
}
}
int main(){
int t,n;
init();
scanf("%d",&t);
while(t--){
scanf("%d",&n);
cout<<f[n]<<endl;
}
return 0;
}