3525:上台阶

3525:上台阶

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可以一步上2阶,也可以一步上3阶,编程计算共有多少种不同的走法。

输入
输入的每一行包括一组测试数据,即为台阶数n。最后一行为0,表示测试结束。
输出
每一行输出对应一行输入的结果,即为走法的数目。
样例输入
1
2
3
4
0
样例输出
1
2
4
7

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<cmath>
 5 using namespace std;
 6 int tot=0;
 7 int find(int n)
 8 {
 9     if(n==1)return 1;
10     else if(n==2) return 2;
11     else if(n==3) return 4;
12     else return find(n-3)+find(n-2)+find(n-1);
13 }
14 int main() {
15     int a,b;
16     while(cin>>a)
17     {
18         if(a==0)break;
19         else 
20         cout<<find(a)<<endl;
21     }
22     return 0;
23 }

 

posted @ 2017-03-04 20:24  自为风月马前卒  阅读(550)  评论(0编辑  收藏  举报

Contact with me