POJ 3783 Balls

来源:互联网 发布:mac需要用户名登录 编辑:程序博客网 时间:2024/06/05 11:38
题目链接 : POJ3783
 
Balls
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 381 Accepted: 274

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 42 143 24
4 10

Source

Greater New York Regional 2009
 
 
好像是第一个写的dp题   以后补
 
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<string>#include<vector>#include<iostream>#include<map>using namespace std;#define INF 0x7fffffffint dp[55][1005];int ans[55][1005];void sol(){dp[1][1]=1;for(int i=1;i<51;i++)for(int j=1;j<1001;j++)dp[i][j]=min(1000,dp[i-1][j-1]+dp[i][j-1]+1);for(int i=1;i<51;i++)for(int j=1;j<1001;j++){if(ans[i][dp[i][j]]==0) ans[i][dp[i][j]]=j;}}int main(){sol();int n;scanf("%d",&n);while(n--){int a,b,c,fin;scanf("%d%d%d",&a,&b,&c);fin=ans[b][c];while(fin==0) fin=ans[b][++c];printf("%d %d\n",a,fin);}return 0;}

 
 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 被螃蟹夹了肿了怎么办 吃了死了的螃蟹怎么办 被沙漠蝎子咬到怎么办 明台手表掉了怎么办 如果撞了豪车怎么办 车子陷到泥巴里怎么办 乳房一生气就疼怎么办 4s屏幕不显示怎么办 雷神红蜘蛛掉漆怎么办 桔子树根部霉了怎么办 电脑u盘被禁用怎么办 机房u盘限制了怎么办 蜘蛛爬到人身上怎么办 房间里有蛐蛐叫怎么办 养的雨林蝎跑了怎么办 多肉长得太高了怎么办 手被蝎子咬了怎么办 被蝎子蛰住了怎么办 小孩被蝎子蜇了怎么办 孕妇被蝎子蛰了怎么办 怀孕被蝎子蜇了怎么办 孩子被蝎子蛰了怎么办 手被蝎子蛰了怎么办 被东亚钳蝎蛰了怎么办 孕37周羊水过多怎么办 孕38周羊水过多怎么办 孕39周羊水过多怎么办 生完孩子腿关节疼怎么办 手指上长了倒刺怎么办 肥肉吃多了恶心怎么办 大便粘稠怎么回事还便秘怎么办 狗狗大便次数多怎么办 宝宝拉白色稀便怎么办 5个月宝宝流鼻涕怎么办 5个月婴儿流鼻涕怎么办 五个月宝宝流鼻涕鼻塞怎么办 4个月宝宝流鼻涕怎么办 大便经常是稀的怎么办 拉黑色的稀大便怎么办 孕晚期半夜饿了怎么办 肠胃不好大便不成型怎么办