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

1979-爬楼梯

热度:56   发布时间:2023-12-29 15:36:14.0

【C系列4.11】函数训练之爬楼梯 1979

Time Limit:  1 s      Memory Limit:   32 MB
Submission:104     AC:90     Score:20.31

 

Description

cyn小朋友今天学会了如何爬楼梯,但她腿太短了,能走的步数不多,你能帮她算算他的走法总共有几种吗?假设有h个楼梯,一次只能走一步或者两步或者三步,求总共有几种不同的方法

Input

第一行输入一个整数T,代表有几组测试数据。
接下来每行输入一个整数h(less than 30),代表有几个楼梯。

Output

输出有几种方法。

Samples

input:
3
10
20
30
output:
274
121415
53798080


下附AC代码:

#include<stdio.h>
int steps(int n);
int main() {int n, s, t;scanf("%d", &t);while (t--) {scanf("%d", &n);s = steps(n);printf("%d\n", s);}return 0;
}
int steps(int n) {if (1 == n)return 1;if (2 == n)return 2;if (3 == n)return 4;return steps(n - 1) + steps(n - 2) + steps(n - 3);
}


原题链接:http://acm.hznu.edu.cn/OJ/problem.php?cid=1092&pid=12