哈理工OJ 1124 Final Destination(简单递推)
2016-05-15 21:43
357 查看
Final Destination
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 599(188 users) Total Accepted: 195(175 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.
一道简单的递推题目,有个坑点,dp[0]=1;
递推过程,当目的地大于3的时候,他前面的三个点都能直接到达这个点。
所以可以得到以下的递推关系式:
i=0;dp[0]=1;
i=1;dp[1]=1;
i=2;dp[2]=2;
i=3;dp[3]=4
i>3时
dp[i]=dp[i-1]+dp[i-2]+dp[i-3]
下面是AC代码:
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 599(188 users) Total Accepted: 195(175 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.
一道简单的递推题目,有个坑点,dp[0]=1;
递推过程,当目的地大于3的时候,他前面的三个点都能直接到达这个点。
所以可以得到以下的递推关系式:
i=0;dp[0]=1;
i=1;dp[1]=1;
i=2;dp[2]=2;
i=3;dp[3]=4
i>3时
dp[i]=dp[i-1]+dp[i-2]+dp[i-3]
下面是AC代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int fib[45]; int main() { fib[0]=1,fib[1]=1,fib[2]=2,fib[3]=4;; for(int i=4;i<40;i++) { fib[i]=fib[i-1]+fib[i-2]+fib[i-3]; } int t,n,iCase=0; scanf("%d",&t); while(t--) { iCase++; scanf("%d",&n); printf("Case %d:\n",iCase); printf("%d\n",fib ); } return 0; }
相关文章推荐
- 第三章 Python基础
- ZLYD团队第一周项目总结
- Linux上安装Java环境与Tomcat
- 周赛题(2016"百度之星" - 资格赛(Astar Round1))
- Java回调机制(CallBack)
- 分页加载my
- http://www.cnblogs.com/shortboy/p/4429368.html
- prime
- 毕设之Opencv批量圆拟合
- postgres configure help
- C++——构造函数的不同调用情况
- Http百度请求数据
- http://blog.csdn.net/rosten/article/details/17068285
- 分层基础
- 机房合作那些图
- Common Lisp入门笔记(四)函数
- PAT L2-007. 家庭房产 (并查集)
- 菜鸟:模拟栈和队列的push和pop
- js,jquery,不能通过true/false控制radio的选中状态,prop,attr,
- 运维网络基础