C

Description

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

Input

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

Output

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

Sample Input

2
2
3

Sample Output

1
2
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define maxn 100
#define oo 0x3f3f3f
#define PI 3.1415926535897932
int n;
int k;
long long dp[maxn];
void init()
{
    for(int i=4; i<=maxn; i++)
        dp[i] = dp[i-2] + dp[i-1];
}
int main()
{
    int t,m;
    scanf("%d",&t);

    while(t--)
    {
        scanf("%d",&m);
        dp[1] = 1;
        dp[2] = 1;
        dp[3] = 2;

        init();

        printf("%I64d
",dp[m]);

    }
    return 0;
}
原文地址:https://www.cnblogs.com/biu-biu-biu-/p/5744496.html