Hust oj 1124 Final Destination(递推)

Final Destination
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 600(189 users)Total Accepted: 196(176 users)Rating: Special Judge: No
Description

JiaoZhu likes going on adventure! One day, he walks into a big castle, and there is an unique stairway. JiaoZhu finds a board ,it says “The one who want to go upstairs only can go three steps the most once, meaning that you can go 1 or 2 or 3 steps once!”. Now, we have a problem, can you tell me the number of ways to go to the destination? If you can’t ,death is the only choice

In the beginning, you are in the 0th step. 

Input

First input a integer T(T<50), represent the number of case.

Each case ,the input will consist only a positive integer n (0<=n<=30), represent the nth steps you want to go to..

Output

Order the sample output format to output.

Line 1,print the Case k.

Line 2,print one integer represent the number of ways to go to nth steps.

Sample Input
2
1
2
Sample Output
Case 1:
1
Case 2:
2
Hint

When n=2,you can go one step once to go to 2th ,or go 2 steps once to 2th,so the answer is 2.

Author

万祥

当前状态可以从前三步转移过来,所以很显然a[I] = a[I-1]+a[I-2]+a[I-3]

#include<cstdio>
using namespace std;

const int maxn = 100;
int a[maxn];
int n;

int main()
{
    a[0] = 1;
    a[1] = 1;
    for(int i=2;i<50;i++)
    {
        a[i] = a[i-1] + a[i-2];
    }
    while(~scanf("%d",&n) && n)
    {
        printf("%d\n",a[n]);
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值