Problem 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

For each case of the input, print one line of output giving the minimum number of trials needed to solve the problem. If more than 63 trials are needed then print ‘More than 63 trials needed.’ instead of the number.
 

 Sample Input

2 100
10 786599
4 786599
60 1844674407370955161
63 9223372036854775807
0 0
 

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!(动态规划)的更多相关文章

  1. 【杂题总汇】UVa-1627 Team them up!

    [UVa-1627] Team them up! 借鉴了一下hahalidaxin的博客……了解了思路,但是莫名Wa了:最后再找了一篇dwtfukgv的博客才做出来

  2. uva1627 Team them up!

    注意这题要求互相认识不认识的人之间连一条线一个人在组1,那么不认识(互相认识)的人就在组0:同时这些人不认识的人就在组1.每个联通分量都可以独立推导,遇到矛盾则无解一个联通分量有一个核心,其他的点是分 ...

  3. 【暑假】[深入动态规划]UVa 1627 Team them up!

    UVa 1627 Team them up! 题目: Team them up! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Forma ...

  4. BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...

  5. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

  6. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  7. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  8. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  9. F - Free DIY Tour(动态规划,搜索也行)

    这道题可用动态规划也可以用搜索,下面都写一下 Description Weiwei is a software engineer of ShiningSoft. He has just excelle ...

  10. poj 动态规划的主题列表和总结

    此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...

随机推荐

  1. mysql各种操作记录

    MySQL设置数据集为UTF8仍无法输入中文的解决办法: mysql -uroot -p --default-character-set=gbk 可用命令status 和 show variables ...

  2. sqlserver 2008R2新建数据库时报错,提示无法获得数据库"model"上的排它锁

    刚新装了个sqlserver2008 R2,在建立数据库时候报错,提示无法获得数据库"model"上的排它锁.解决办法如下: 打开查询页面,执行下面的语句即可. use maste ...

  3. 精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!

    原文:https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with-duplicates 作者:Chalaran ...

  4. 将HTML页面自动保存为PDF文件并上传的两种方式(一)-前端(react)方式

    一.业务场景 公司的样本检测报告以React页面的形式生成,已调整为A4大小的样式并已实现分页,业务上需要将这个网页生成PDF文件,并上传到服务器,后续会将这个文件发送给客户(这里不考虑). 二.原来 ...

  5. HTML元素被定义为块级元素或内联元素。那么什么是块级元素,什么是内联元素呢

    块级元素(block)特性: 块级元素在浏览器显示时,通常会以新行来开始(和结束). 宽度(width).高度(height).内边距(padding)和外边距(margin)都可控制;就像以前用到的 ...

  6. phpcms中content主要使用的详情列表关系

    从首页(index.html)中点开的内容网页叫单网页(page.html) 从列表(list.html)中点开的网页叫内容页(show.html) 从导航栏的栏目中下拉的列表栏目叫栏目列表页(cat ...

  7. 网络基础 记一次HTTPS证书验证测试过程

    记一次HTTPS证书验证测试过程 by:授客 QQ:1033553122 实践 1) 安装证书 选择主机A(假设10.202.95.88)上安装https证书 说明:采用https的服务器,必须安装数 ...

  8. ERP承接新后台优惠规则问题

    一.后台在哪配置优惠规则? 1.设置优惠时间段: 2.添加优惠活动: 关于自动和手动: 自动:创建后,ERP同步数据后即生效.     点餐,活动会自动生效,自动计算金额. 手动:创建后,ERP需要手 ...

  9. Scala隐式参数

    Scala方法可以具有隐式参数列表,由参数列表开头的implicit关键字标记.如果参数列表中的参数没有像往常一样传递,Scala将查看它是否可以获得正确类型的隐式值,如果可以,将自动传递. Scal ...

  10. Could not update the distribution database subscription table. The subscription status could not be changed.

    在一个测试服务器删除发布(Publication)时遇到下面错误,具体如下所示 标题: Microsoft SQL Server Management Studio   --------------- ...