Final Destination | ||||||
| ||||||
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]
|
Hust oj 1124 Final Destination(递推)
最新推荐文章于 2021-11-10 21:19:09 发布