您的位置:首页 > 其它

超级楼梯 2041

2014-03-17 17:15 127 查看
Problem Description

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

Input

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

Output

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

Sample Input

2

2

3

Sample Output

1

2

#include <iostream>

int main(int argc, const char *argv[])
{
__int64 result[45] = {1, 1, 2};
for(int i = 3;i < 45;++ i)
{
result[i] = result[i - 1] + result[i - 2];
}

int n = 0;
std::cin >> n;
while(n --)
{
int m = 0;
std::cin >> m;
std::cout << result[m - 1] << std::endl;
}

//system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: