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

问题链接:UVA10934 Dropping water balloons
问题简述:给定n个气球和大楼的高度,求最少试验几次能测出气球最高在哪一层掉下来不破。
问题分析:经典的DP问题。
dp[i][j]表示用i个气球,测试出j高的楼。
状态转换方程如下:
dp[i][j] = 1
dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + 1
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10934 Dropping water balloons */#include <bits/stdc++.h>using namespace std;typedef unsigned long long ULL;
const int K = 100, B = 64;
ULL dp[K + 1][B];void init()
{for (int i = 1; i <= K; i++)for (int j = 1; j < B; j++)if (j == 1) dp[i][j] = 1;else dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + 1;
}int main()
{init();int k, i;ULL n;while (~scanf("%d%llu", &k, &n) && k) {for (i = 1; i < B; i++)if (dp[k][i] >= n) break;if (i >= B) puts("More than 63 trials needed.");else printf("%d\n", i);}return 0;
}

UVA10934 Dropping water balloons【DP】相关推荐

  1. UVa 10934 Dropping water balloons:dp(递推)

    题目链接:https://vjudge.net/problem/27377/origin 题意: 有一栋n层高的楼,并给你k个水球.在一定高度及以上将水球扔下,水球会摔破:在这个高度以下扔,水球不会摔 ...

  2. 【DP】【期望】$P1850$换教室

    [DP][期望]\(P1850\)换教室 链接 题目描述 有 \(2n\) 节课程安排在$ n$ 个时间段上.在第 \(i\)(\(1 \leq i \leq n\))个时间段上,两节内容相同的课程同 ...

  3. Bailian2760 数字三角形【DP】

    2760:数字三角形 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径.对于每条路径,把路径上面的数加起来可 ...

  4. NUC1131 Triangle【DP】

    Triangle 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 图1表示一个数字三角形. 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ...

  5. LeetCode:完全平方数【279】【DP】

    LeetCode:完全平方数[279][DP] 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示 ...

  6. 【DP】序列 题解

    [DP]序列 题解 序列 题目 一个长度为kkk的整数序列bbb 1,bbb 2,-,bkbkbk(1≤bbb 1≤bbb 2≤-≤bkbkbk≤NNN)称为"好序列"当且仅当后一 ...

  7. 【Uva 10934】Dropping water balloons

    [Link]: [Description] 等价题意: 某人在1..n内选一个数x; 然后让你去猜; 你可以问他是不是在哪个范围里; 每次会告诉你YES或者NO; 问你在最坏的情况下猜出答案需要猜多少 ...

  8. poj 2411 Mondriaan#39;s Dream 【dp】

    题目:poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然后问你最多由多少种不同的方案. 分析:这是一个比較经典的题目.网上各种牛B写法一大堆. ...

  9. BestCoder冠军赛 - 1005 Game 【DP】

    [题意] 给出一个set,set中有几个数. 现在给出n个人,环成一圈搞约瑟夫... 开始时从第1号报数,每次从set中随机选出一个数s,等报数到s后,报s的人出圈,其他人继续报数. 最后只剩1人时, ...

最新文章

  1. access突然需要登录_早知道早好,微信小程序登录开发需要注意的事项
  2. 操作系统 进程调度-银行家算法实验报告
  3. python 解析xml
  4. Specify compute hosts with SSDs
  5. js改变css样式_React 中使用CSS的7种方法
  6. linux 进程间通信 dbus-glib【实例】详解一(附代码)(d-feet工具使用)
  7. iOS项目组件化历程
  8. Linux中,文件创建的时间是怎么保存的?
  9. Python中代码书写规范与基本使用
  10. ajax数据显示,使用js通用模板
  11. littlevgl抗锯齿_littlevgl架构浅析
  12. python通过类名创建对象_如何在Python中为自动创建的类对象分配名称
  13. Java 基础高频面试题(2022年最新版)
  14. Pr入门系列之十一:基本图形(上)
  15. 《JavaScript 20 年》中文版之语言诞生
  16. vue前端页面素材代码大全
  17. Apollo 的3D障碍物感知解析
  18. ajax怎么传递list类型参数到后端,ajax传递给后台数组参数方式
  19. 生成百度网盘文件目录_艾孜尔江撰稿
  20. 海思开发板上添加ftp功能

热门文章

  1. 电脑打字学习_高邮学习商务办公难不难?/电脑办公的学习内容有哪些? - 教育培训消费 - 得意生活...
  2. 表单和ajax中的post请求后台获取数据方法(深度好文)
  3. MySQL涉及的时间函数
  4. scala中的filter函数
  5. python里 t_python中的“.T”操作
  6. 雷军:我爱编程这个工作,可以肯定我会干上一辈子
  7. flamingo源码分析(1) :单例模式
  8. 大数据系列2-liunx基础-2基本操作
  9. 指数分布的定义形式及应用
  10. Delphi Open Tools Api实例研究(一)