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. 使用virtualenv进行python环境隔离

    按照以下步骤安装 TensorFlow: 1.打开终端(一个 shell),你将在这个终端中执行随后的步骤 2.通过以下命令安装 pip 和 virtualenv sudo easy_install ...

  2. LINUX sed grep awk之间比较整理

    正则表达式基础 在最简单的情况下,一个正则表达式看上去就是一个普通的查找串.例如,正则表达式"testing"中没有包含任何元字符,,它可以匹配"testing" ...

  3. 填一个laravel视图缓存没有及时更新的坑

    1.此坑背景 laravel在渲染blade模板后,会将渲染好的结果存到storage/framework/views(默认路径,也可在配置中修改的)中,以便下次使用.但我最近总是发现修改了blade ...

  4. jQuery 练习:tab 切换

    实现内容随菜单切换 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. php小程序登录时解密getUserInfo获取openId和unionId等敏感信息

    在获取之前先了解一下openId和unionId openId : 用户在当前小程序的唯一标识 unionId : 如果开发者拥有多个移动应用.网站应用.和公众帐号(包括小程序),可通过unionid ...

  6. 2018-07-30 对DLL库中的接口进行中文命名

    补注: 此文是在探究在Windows上编写DLL时不能使用中文命名 · Issue #74 · program-in-chinese/overview问题时编写的演示用代码, 代码基于官方文档. 正如 ...

  7. iOS------自动查找项目中不用的图片资源

    注意:删除的时候要谨慎!别什么图都删了,看看对项目有没有作用.这个插件有时也会有一定的误差. 具体操作步骤: 1.去github上下载LSUnusedResources(下载地址:https://gi ...

  8. android 圆角背景

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

  9. java垃圾回收机制GC

    记得第一次总结java 的GC的时候,是刚开始在课堂上学习GC的时候,那时候许老师第一节java课 课后老师说同学们可以去深入理解一下java的GC机制: 但是是花费了三四个小时,翻看了<Thi ...

  10. spring boot 基础 2018年5月3日

    主包下运行类@SpringBootApplication  此注解是核心注解,源码如下 @Target({ElementType.TYPE}) @Retention(RetentionPolicy.R ...