UVA1627-Team them up!(动态规划)
Total Submissions:3577 Solved:648
Time Limit: 3000 mSec
Problem Description
It’s frosh week, and this year your friends have decided that they would initiate the new computer science students by dropping water balloons on them. They’ve filled up a large crate of identical water balloons, ready for the event. But as fate would have it, the balloons turned out to be rather tough, and can be dropped from a height of several stories without bursting! So your friends have sought you out for help. They plan to drop the balloons from a tall building on campus, but would like to spend as little effort as possible hauling their balloons up the stairs, so they would like to know the lowest floor from which they can drop the balloons so that they do burst. You know the building has n floors, and your friends have given you k identical balloons which you may use (and break) during your trials to find their answer. Since you are also lazy, you would like to determine the minimum number of trials you must conduct in order to determine with absolute certainty the lowest floor from which you can drop a balloon so that it bursts (or in the worst case, that the balloons will not burst even when dropped from the top floor). A trial consists of dropping a balloon from a certain floor. If a balloon fails to burst for a trial, you can fetch it and use it again for another trial.
Input
The input consists of a number of test cases, one case per line. The data for one test case consists of two numbers k and n, 1 ≤ k ≤ 100 and a positive n that fits into a 64 bit integer (yes, it’s a very tall building). The last case has k = 0 and should not be processed.
Output
Sample Input
Sample Output
14
21
More than 63 trials needed.
61
63
题解:这个题属于比较经典的动态规划题,dp(i,j)表示i个水球,做j次实验能够测出的最高楼层,考虑第一个水球,将其在第k层扔下,如果炸了,那就说明硬度<k,为了能够在剩下的i-1个水球和j-1次实验机会中测出硬度,必须要求k-1<=dp(i-1,j-1),也就是说k最大dp(i-1,j-1)+1,如果没炸,那么k+1层相当于新的1层,还有i个球,j-1次机会,能够测到的楼层自然是dp(i-1,j),因此加上前面的,就是总共能测得最高的。
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = + ; int k;
LL n, dp[maxn][]; LL DP(int k, int i) {
if (dp[k][i] > ) return dp[k][i];
if (!k || !i) return dp[k][i] = ; return dp[k][i] = DP(k - , i - ) + DP(k, i - ) + ;
} int main()
{
//freopen("input.txt", "r", stdin);
memset(dp, -, sizeof(dp));
while (~scanf("%d%lld", &k, &n) && k) {
int i;
for (i = ; i <= ; i++) {
if (DP(k, i) >= n) {
printf("%d\n", i);
break;
}
}
if (i == ) printf("More than 63 trials needed.\n");
}
return ;
}
UVA1627-Team them up!(动态规划)的更多相关文章
- 【杂题总汇】UVa-1627 Team them up!
[UVa-1627] Team them up! 借鉴了一下hahalidaxin的博客……了解了思路,但是莫名Wa了:最后再找了一篇dwtfukgv的博客才做出来
- uva1627 Team them up!
注意这题要求互相认识不认识的人之间连一条线一个人在组1,那么不认识(互相认识)的人就在组0:同时这些人不认识的人就在组1.每个联通分量都可以独立推导,遇到矛盾则无解一个联通分量有一个核心,其他的点是分 ...
- 【暑假】[深入动态规划]UVa 1627 Team them up!
UVa 1627 Team them up! 题目: Team them up! Time Limit: 3000MS Memory Limit: Unknown 64bit IO Forma ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- F - Free DIY Tour(动态规划,搜索也行)
这道题可用动态规划也可以用搜索,下面都写一下 Description Weiwei is a software engineer of ShiningSoft. He has just excelle ...
- poj 动态规划的主题列表和总结
此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...
随机推荐
- Python-10行代码实现3个数据可视化
阅读本文约“1分钟” 最近将Python作为第二编程语言,进行了了解与学习,可以说它的包是很强大的.这次的demo仅仅不到10行代码就可以实现三个数据可视化的小实例. 我们将要使用到matplotli ...
- 51单片机:IO口扩展芯片用法(74HC165,74HC595)
IO口扩展芯片,主要是解决单片机IO口太少. 74HC165:数据从并转串 74HC595:数据从串转并 两种芯片,都是通过时序电路,加上移位功能,进行数据传输 74HC165:数据从并转串.以下实例 ...
- WORLD 快速线
1,3个“-” 一条直线 2,3个“=” 一条双直线 3,3个“*” 一条虚线 4,3个“~” 一条波浪线 5, 3个“#” 一条隔行线
- laravel使用Schema创建数据表
1.简介 迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和Laravel的schema构建器结对从而可以很容易地构建应用的数据库表结构.如果你曾经告知小组成员需要手 ...
- jsp引入本地图片
jsp引入本地图片 通用解决方法: 在tomcat的server.xml配置文件中,在<host></host>标签中间添上一句 <!-- docBase : 磁盘绝对路 ...
- K8S Calico
NetworkPolicy是kubernetes对pod的隔离手段,是宿主机上的一系列iptables规则. Egress 表示出站流量,就是pod作为客户端访问外部服务,pod地址作为源地址.策略可 ...
- MongoDB 通过配置文件启动及注册服务
1.配置mongodb环境变量,配置完成之后就可以直接执行mong.mongod等常用命令,不用每次都到mongodb安装目录bin下去执行: 2.通过命令启动mongo服务 mongod --dbp ...
- SAP MM 没有维护MRP 视图的物料可以正常参与采购业务
SAP MM 没有维护MRP 视图的物料可以正常参与采购业务 Material number: R000006872,没有维护MRP 视图, 也就是没有指定该物料来源是采购还是自制.此种情况下,S ...
- 冒泡排序算法的C++实现
直接上代码: #include <iostream> using namespace std; void BubbleSort(int arr[],int n){ ) //在本例中,第1次 ...
- 常用的JVM调优参数总结汇总【随时查阅学习】
本文章参数根据后期用的参数会持续更新 --- (1)-Xms20M 表示设置JVM启动内存的最小值为20M,必须以M为单位 (2)-Xmx20M 表示设置JVM启动内存的最大值为20M,必须以M为单 ...