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. ABAQUS学习记录1——用户子程序综述

    概述 ABAQUS提供了相当丰富的单元类型,材料属性等数据库可供用户选择,但是工程问题是千变万化的,为了满足用户的特殊工程要求,ABAQUS为用户提供了强大而又灵活的用户子程序接口(USER SUBR ...

  2. 牛客网NOIP赛前集训营-提高组(第二场)A 方差

    链接:https://www.nowcoder.com/acm/contest/173/A来源:牛客网 题目描述 一个长度为 m 的序列 b[1...m] ,我们定义它的方差为 ,其中  表示序列的平 ...

  3. oracle数字返回为字符串时小时点前面的0缺失的问题

    SELECT 0.001||'' from dual UNION SELECT TO_CHAR(0.001||'','fm999990.99999') from dual;

  4. 解决 【xshell 5 不能使用退格键和Delete建】的问题

    ###按照图片操作即可 1,打开[文件],选择[打开]选项 2.在会话中,打开[属性] 3.点击左边[终端]下的[键盘]选项,按照如下设置 即可.

  5. 360 Atlas中间件安装及使用

    1.下载Atlas wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm ...

  6. CSS小知识点一

    1.   text-indent属性    缩进文本 通过使用 text-indent 属性,所有元素的第一行都可以缩进一个给定的长度,甚至该长度可以是负值.这个属性最常见的用途是将段落的首行缩进,一 ...

  7. Android ShapeDrawable之OvalShape、RectShape、PaintDrawable、ArcShape

     Android ShapeDrawable之OvalShape.RectShape.PaintDrawable.ArcShape Android图形图像基础之OvalShape.RectShap ...

  8. [HNOI2004]宠物收养场(Treap)

    洛谷传送门 这题真是恶心,一开始没理解题意. 原来如果有狗,狗就会存在收养场中,直到有人来领养: 如果有人,人也会存在收养场中,直到有狗来被领养. 就是建一个treap,狗来把狗插进去,人来后把狗领养 ...

  9. 51nod1135 原根

    原根判定:$m>2$,$\varphi (m)$的不同素数是$q_1,q_2,……,q_s$,$(g,m)=1$,则$g$是$m$的一个原根的充要条件是$g^{\frac{\varphi(m)} ...

  10. msp430项目编程16

    msp430中项目---电子秒表 1.定时器工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习