当前位置: 代码迷 >> 综合 >> 爬楼梯 oj
  详细解决方案

爬楼梯 oj

热度:18   发布时间:2024-01-14 22:44:39.0

爬楼梯

Time Limit: 1000 ms  Memory Limit: 65536 KiB
Submit  Statistic
Problem Description

小明是个非常无聊的人,他每天都会思考一些奇怪的问题,比如爬楼梯的时候,他就会想,如果每次可以上一级台阶或者两级台阶,那么上 n 级台阶一共有多少种方案?

Input

输入包含多组测试数据,对于每组测试数据:
输入只有一行为一个正整数 n(1 ≤ n ≤ 50)。

Output

对于每组测试数据,输出符合条件的方案数。
注意:64-bit 整型请使用 long long 来定义,并且使用 %lld 或 cin、cout 来输入输出,请不要使用 __int64 和 %I64d。

Sample Input
2
4
Sample Output
2
5
Hint
Source
#include <stdio.h>
#include <stdlib.h>int main()
{long long int a[101];int i,n;a[1] = 1,a[2] = 2,a[3] = 3;while(scanf("%d",&n) != EOF){for(i = 3;i <= n;i++){a[i] = a[i - 1] + a[i - 2];}printf("%lld\n",a[n]);}return 0;
}
  相关解决方案