3525:上台阶
查看
提交
统计
提问
总时间限制:
1000ms
内存限制:
65536kB
描述
楼梯有n(100 > n > 0)阶台阶,上楼时可以一步上1阶,也可以一步上2阶,也可以一步上3阶,编程计算共有多少种不同的走法。
输入
输入的每一行包括一组测试数据,即为台阶数n。最后一行为0,表示测试结束。
输出
每一行输出对应一行输入的结果,即为走法的数目。
样例输入
1
2
3
4
0
样例输出
1
2
4
7
状态: Accepted
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
int tot=0,b[105],x[105],i=1;
int find(int n)
{
if(n==1) return 1;
else if(n==2) return 2;
else if(n==3) return 4;
else if(x[n]) return x[n];
else
{ x[n]=find(n-3)+find(n-2)+find(n-1);
return x[n];
}
}
int main()
{
int a;
while(cin>>a)
{
if(a==0)break;
else
{
b[i]=a;
i++;
}
}
for(int j=1;j<i;j++)
cout<<find(b[j])<<endl;
return 0;
}