Catching the Thief

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 653    Accepted Submission(s): 359

Problem Description
In the Qingshui Village, there's a clever thief and a cleverer police. 



There are N houses in Qingshui Village which are located in a straight line. And the N houses are numbered from 1 to N according to the direction of the line. Two houses are consided to be neighbor of each other if and only if there is no other house between
them.



The thief hides in one of N houses now, and the police tries to find him out. Every day the police will choose a house to check and he will catch the thief if he hides in that house. If the thief survive the arrest of the police, in the night he will move to
a neighboring house to pass through the next day.



What is the number of days the police needs to catch the thief in the worst case?

Remember that the police is a clever man.


 
Input
In the first line, an integer T (T <= 100) indicates the number of cases. 

T lines follow. Each contains an integer N described above. (1 <= N <= 10000)




 
Output
For each test case, output “Case x: d” in which x is the number of test case counted from one, and d is the number of days before the police catch the thief in the worst case.


 
Sample Input
2
1
2
 
Sample Output
Case 1: 1
Case 2: 2
Hint
Case 1: There is only one room, so the police can catch the thief on the first day.
Case 2: There are two rooms. The police can check room 1 on the first day. The worst case is that the thief is in room 2, but in this case the police
can check room 1 on the second day and will catch the thief for sure.
这道题目首先要解出前面四个的解
房间为一个的时候答案为1天
房间为两个的时候答案为2天
房间为三个的时候答案为2天
房间为四个的时候答案为4天
第五个房子则能够递推。例如以下图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
从左往右走。一步步排除。小偷所在的房子。dp[2]代表着两个房间里最多用多少天能够抓住小偷,如此,我们能够不断递推,先排除,左边两个房间会出现小偷的情况,接着右边还有三个房子,可是为什么图中将第二个房子都给画圈了。由于我们排除了最左边的房子不会出现小偷,可是此时无法防止第二个房子不会再出现小偷。如此要将他算进去,所以dp[5] = dp[2] + dp[4]如此不断递推得出终于的状态转移方程
dp[n] = dp[2] + dp[n - 1]
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 10000 + 5;
LL dp[MAXN];
int n, T;
void init(){
dp[1]=1;
dp[2] = 2;
dp[3] = 2;
for(int i = 4;i < MAXN;i ++){
dp[i] = dp[2] + dp[i - 1];
}
}
int main(){
init();
int cas = 1;
scanf("%d", &T);
while(T --){
scanf("%d", &n);
printf("Case %d: %I64d\n",cas ++, dp[n]);
}
}

 

HDU 3469 Catching the Thief (博弈 + DP递推)的更多相关文章

  1. hdu 1207 汉诺塔II (DP+递推)

    汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. hdu2089(数位DP 递推形式)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】

    Pokémon GO Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. hdu 2604 Queuing(dp递推)

    昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...

  5. hdu 1723 DP/递推

    题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...

  6. HDU 2154 跳舞毯 | DP | 递推 | 规律

    Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...

  7. HDU 5366 dp 递推

    The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...

  8. hdu 2050 折线分割平面 dp递推 *

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. HDU 6076 Security Check DP递推优化

    Security Check Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

随机推荐

  1. (8) tomcat中管理领域、角色及用户

    srverlet Container或web应用程序本身都可以提供控制web应用程序资源的安全防护 前者称为容器管理的安全防护,或者称为应用程序管理安全防护 通过内嵌机制,tomcat提供一些安全防护 ...

  2. apidoc利用代码注释书写文档

    个人博客同步文章 https://mr-houzi.com/2018/07/... apidoc是一款利用源代码中注释来创建RESTful Web API文档的工具.apidoc可用于C#,Go,Da ...

  3. post processing in CFD

    post post Table of Contents 1. Post-processing 1.1. Reverse flow 1.1.1. reasons 1.1.2. solutions 1.2 ...

  4. Struts2执行原理

    [原理图] [MVC] [执行过程(重要!!!!!)] 1) 客户端浏览器发出请求时,被Tomcat服务器所接收.Tomcat容器将用户的请求封装为HttpServletRequest对象 2) 请求 ...

  5. SPOJ VJudge QTREE - Query on a tree

    Query on a tree Time Limit: 851MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submi ...

  6. 【HDOJ6299】Balanced Sequence(贪心)

    题意:给定n个只有左右括号的序列,要求将它们重新排序使得匹配的括号对数最大. n<=1e5 s[i]<=1e5 sum s[i]<=5e6 思路: 先把每个串内部的匹配数量减去,剩下 ...

  7. php的抽象类

    php的抽象类 //定义一个老虎类 abstract class Tiger{ public abstract function climb(); } //定义一个孟加拉虎类 class MTiger ...

  8. JFinal Weixin 1.5 发布,微信极速 SDK

    原文:http://www.oschina.net/news/67980/jfinal-weixin-1-5-released JFinal Weixin 1.5 大幅完善了对微信公众平台API的支持 ...

  9. python学习之-- 协程

    协程(coroutine)也叫:微线程,是一种用户态的轻量级线程,就是在单线程下实现并发的效果.优点:1:无需线程上下文切换的开销.(就是函数之间来回切换)2:无需原子操作锁定及同步的开销.(如改一个 ...

  10. 51 Nod 1244 莫比乌斯函数前n项和

    积性函数前n项和必看好文 https://blog.csdn.net/skywalkert/article/details/50500009 递归计算的时候要用map记忆化一下,前面的打表会比较快一点 ...