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) ...
随机推荐
- 洛谷—— P1268 树的重量
P1268 树的重量 构造类题目,看不出个所以然来... emmm,只好看题解: 只有两个点,那一条路径就是$ans$ 考虑三个点,那么$3$这个点相对于树上的路径(已经加入树上的边的距离) 为:$( ...
- mac rar文件解压缩
在下载文件时经常遇到RAR格式的压缩文件, 之前从APP Store下载了免费的解压软件, 但是总觉着不好用, 广告信息很多. 好用的软件都要花钱, 所以找到了命令行解决的办法. 步骤如下: 首先需要 ...
- 学习vue之windows下安装live-server 超级详细篇
最近项目要求用vue2.0所以开始着手学习. 前期准备: 下载Node.js 地址:http://nodejs.cn/download/ 选择自己对应的版本,我下载的是.msi 64位的 然后就双击下 ...
- 调试jz2440生成特定后缀的命令
生成dis命令: arm-linux-objdump -D u-boot> u-boot.dis 版权声明:本文为博主原创文章,未经博主允许不得转载.
- IBM MQ 创建以及常见问题集锦
消息队列+发送队列+消息通道 接收通道名称与发送端的发送通道名称要一致,修改通道信息后要执行 start channle(chlname) 重启通道.常用的MQ命令 66.0.42.240 用户 mq ...
- 【概率dp】C. Race to 1 Again
https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/C [题意] 给定一个数D,每次随机选取这个数的一个因子x得到新的数D=D/x,知 ...
- Hotel(poj 3667)
题意:询问区间最长连续空串 /* 用线段树维护区间最长连续左空串和右空串 */ #include<cstdio> #include<iostream> #define N 50 ...
- 【HDOJ6335】Nothing is Impossible(贪心)
题意: 有n道题目m个人,每道题目有1个正确选项和a[i]个错误选项,每个人每道题只能选一个选项 求出最坏情况下分数最多的人至少能拿到几分 n<=1e2,m<=1e9,1<=b[i] ...
- OC-category 为什么不能添加成员变量
以下的答案是百度的,仅做记录而已: 1. 利用运行时实际上也不是添加成员变量.已编译的类的内存布局是不变的,Class就是一个结构体,里面的成员不能改变.但是通过运行时可以将一个对象或基础类型变成指定 ...
- BZOJ 1798:
6: LAZY 线段树有乘法的更新 #include <cstdio> #include <cstring> #include <algorithm&g ...