HDU 3469 Catching the Thief (博弈 + DP递推)
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
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.
T lines follow. Each contains an integer N described above. (1 <= N <= 10000)
2
1
2
Case 1: 1
Case 2: 2HintCase 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递推)的更多相关文章
- hdu 1207 汉诺塔II (DP+递推)
汉诺塔II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu2089(数位DP 递推形式)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 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 ...
- hdu 2604 Queuing(dp递推)
昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...
- hdu 1723 DP/递推
题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...
- HDU 2154 跳舞毯 | DP | 递推 | 规律
Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...
- HDU 5366 dp 递推
The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu 2050 折线分割平面 dp递推 *
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 6076 Security Check DP递推优化
Security Check Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) ...
随机推荐
- 2019天梯赛练习题(L1专项练习)
7-1 水仙花数 (20 分) 水仙花数是指一个N位正整数(N≥3),它的每个位上的数字的N次幂之和等于它本身.例如:1. 本题要求编写程序,计算所有N位水仙花数. 输入样例: 3 输出样例: 153 ...
- 【Linux】Centos6的iptables防火墙设置
1,查看防火墙状态 # service iptables status //或 # /etc/init.d/iptables status 2,防火墙的启动.重启,关闭 # service iptab ...
- GitLab 安装和配置
一.GitLab 简介 GitLab 是一个利用Ruby on Rails 开发的开源版本控制系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. 它拥有与GitHub类 ...
- Python+selenium鼠标、键盘事件
鼠标操作 现在的Web产品提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在Webdriver中,将这些关于鼠标操作的方法封装在ActionChains类提供. 1.鼠标右击 ...
- LoadRunner之并发用户数与迭代关系---并发数与迭代的区别
Q1: 例如在LR里,我要测100个用户同时并发登陆所用时间,那我是不是在录制好脚本后,需要参数化“用户名”,“密码”以及在那个记事本里构造100个真实的用户名和密码? 然后运行Controller, ...
- NYOJ-116士兵杀敌(二),树状数组~~
士兵杀敌(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军经常想知 ...
- hdu 1563简单异或Find your present!
#include<stdio.h> int main(){ int n,m,s; while(scanf("%d",&n),n) { s=0; w ...
- Linux(5):正则表达式 & 权限
正则表达式: 特殊符号: '' ---> 所见即所得,里面的内容都会被原封不动的输出出来 "" ---> 与单引号类似,但其中的特殊符号会被解析运行 `` ---> ...
- Circling Round Treasures(codeforces 375c)
题意:要求在一张网格图上走出一条闭合路径,不得将炸弹包围进去,使围出的总价值减去路径长度最大. /* 类似于poj3182的做法,只不过出现了多个点,那么就用状态压缩的方法记录一个集合即可. */ # ...
- 【收藏】下载Chrome商店插件的方法,万恶的gwd
以下是下载离线插件包的方法: 第一步: 每个Google Chrome扩展都有一个固定的ID,例如https://chrome.google.com/webstore/detail/bfbmjmiod ...