Balls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1110   Accepted: 721

Description

The classic Two Glass Balls brain-teaser is often posed as:

"Given two identical glass spheres, you would like to determine the lowest floor in a 100-story building from which they will break when dropped. Assume the spheres are undamaged when dropped below this point. What is the strategy that will minimize the worst-case scenario for number of drops?"

Suppose that we had only one ball. We'd have to drop from each floor from 1 to 100 in sequence, requiring 100 drops in the worst case.

Now consider the case where we have two balls. Suppose we drop the first ball from floor n. If it breaks we're in the case where we have one ball remaining and we need to drop from floors 1 to n-1 in sequence, yielding n drops in the worst case (the first ball is dropped once, the second at most n-1 times). However, if it does not break when dropped from floor n, we have reduced the problem to dropping from floors n+1 to 100. In either case we must keep in mind that we've already used one drop. So the minimum number of drops, in the worst case, is the minimum over all n.

You will write a program to determine the minimum number of drops required, in the worst case, given B balls and an M-story building.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing three(3) decimal integer values: the problem number, followed by a space, followed by the number of balls B, (1 ≤ B ≤ 50), followed by a space and the number of floors in the building M, (1 ≤ M ≤ 1000).

Output

For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the minimum number of drops needed for the corresponding values of B and M.

Sample Input

4
1 2 10
2 2 100
3 2 300
4 25 900

Sample Output

1 4
2 14
3 24
4 10

Source

题目大意:鹰蛋问题.n个蛋,m层楼. 存在一层楼E,使得E以及E以下的楼层鹰蛋都不会摔碎,问最坏情况下最少多少次能够知道E.
分析:这是一道神奇的题目.不仅仅是题目类型非常特别,优化也很多.具体的优化可以去看论文:传送门,这里只想说说这类问题如何下手.
   题目的目的是最小化最大值,似乎可以二分?可是什么都不知道要怎么判断可行性啊......正确的解法是dp.状态很明显:
   f[i][j]表示i个蛋,确定j层楼的E的答案. 如果当前在第k层扔蛋,两种可能:
   1.蛋碎了,那么还剩下i-1个蛋,第j层不是E层,还有j-1层需要确定,可以从f[i-1][j-1]转移而来. 
   2.蛋没碎,还剩下i个蛋,第k层以下都不可能是E层了,还剩下j-k层需要确定.那么从f[i][j - k]转移而来. 注意,这里的从上往下数j-k层和从下往上数j-k层本质上是没有区别的,所以可以把这j-k层看作一个新的高j-k层的楼.
   接着就是重中之重了,如何转移? 事情总是朝着最坏的方向发展的. 第k层会不会摔碎实际上是不能确定的!要从最坏的状态转移而来!那么状态转移方程就是:f[i][j] = min{max{f[i-1][j-1],f[i][j - k]} + 1,f[i][j]}. 
   脑洞不大的话理解起来确实有点困难,比较好的方法是倒着看.从第k层状态的不确定性来从最坏的情况转移而来.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int inf = 0x7ffffff;
int T;
int cas,n,m,f[][]; void solve()
{
memset(f,/,sizeof(f));
for (int i = ; i <= n; i++)
f[i][] = ;
for (int i = ; i <= m; i++)
f[][i] = i;
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
for (int k = ; k <= j; k++)
f[i][j] = min(f[i][j],max(f[i - ][k - ],f[i][j - k]) + );
} int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&cas,&n,&m);
solve();
printf("%d %d\n",cas,f[n][m]);
} return ;
}

poj3783 Balls的更多相关文章

  1. [POJ3783]Balls 题解

    题目大意 鹰蛋问题.$ n\(个蛋,\)m\(层楼. 存在一层楼\)E\(,使得\)E\(以及\)E\(以下的楼层鹰蛋都不会摔碎,问最坏情况下最少多少次能够知道\)E$. 非常经典的模型,初看题目根本 ...

  2. HDU5781 ATM Mechine(DP 期望)

    应该是machine 和POJ3783 Balls类型相似. 现在上界为i元,猜错次数最多为j时,开始猜测为k元,有两种情况: 1 猜中:(i - k + 1) * dp[i - k][j] 2 猜不 ...

  3. 蓝桥杯-摔手机问题【dp】

    非常详细的题解:戳这里 例题:poj-3783 Balls Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 115 ...

  4. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  5. 13 Balls Problem

    今天讨论的是称球问题. No.3 13 balls problem You are given 13 balls. The odd ball may be either heavier or ligh ...

  6. Open judge C16H:Magical Balls 快速幂+逆元

    C16H:Magical Balls 总时间限制:  1000ms 内存限制:  262144kB 描述 Wenwen has a magical ball. When put on an infin ...

  7. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  8. hdu 3635 Dragon Balls(并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. POJ 3687 Labeling Balls()

    Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: 2636 Descri ...

随机推荐

  1. Docker运行简单的Demo

    打开cmd.exe 输入docker run hello-world,本机没有这个images实例,将会从官方下载下载 运行一个简单的web实例,例如输入: docker run --name asp ...

  2. rz和sz上传下载文件

    安装软件包 yum install  lrzsz   上传文件,输入rz选择文件上传(可以按住shift键多选) # rz   sz 下载文件到本地,选择保存文件夹 # sz dd   xshell设 ...

  3. DOM---文档对象模型(Document Object Model)的基本使用

    一.DOM简介 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展置标语言的标准编程接口.它是一种与平台和语言无关的应用程序接口(API),它可以动态 ...

  4. Paper Reading - Mind’s Eye: A Recurrent Visual Representation for Image Caption Generation ( CVPR 2015 )

    Link of the Paper: https://ieeexplore.ieee.org/document/7298856/ A Correlative Paper: Learning a Rec ...

  5. 微软职位内部推荐-Principal Group Program Manager

    微软近期Open的职位: Standard job title: Principal Group Program Manager Discipline: Program Management Prod ...

  6. content-length与Transfer-Encoding: chunked的问题释疑

    http返回头中content-length与Transfer-Encoding: chunked的问题释疑 先说说问题出现的背景: 公司服务器与手机客户端交互,客户端请求一个动态生成的XML文件,在 ...

  7. 月薪45K的Python爬虫工程师告诉你爬虫应该怎么学,太详细了!

    想用Python做爬虫,而你却还不会Python的话,那么这些入门基础知识必不可少.很多小伙伴,特别是在学校的学生,接触到爬虫之后就感觉这个好厉害的样子,我要学.但是却完全不知道从何开始,很迷茫,学的 ...

  8. kylin-note

    http://www.cnblogs.com/tgzhu/category/915975.html https://sdk.cn/news/3566 https://www.linuxidc.com/ ...

  9. Beta阶段第2周/共2周 Scrum立会报告+燃尽图 04

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 版本控制地址    [https://git.coding.net/ ...

  10. 王者荣耀交流协会final发布WBS+PSP

    WBS: PSP: 时间为估计,大致精确. 类型 personal software process stages 预估时间 实际花费时间 planning 计划 4h 4h estimate 4h ...