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;}
- POJ 3783 Balls
- POJ 3783 Balls 动态规划
- POJ 3783 Balls(dp)
- POJ 3783 Balls (线性dp 智力题)
- poj-3783-Balls dp/线性dp
- POJ 3783 ——Balls 【DP】
- poj 3687 Labeling Balls
- POJ 3687 Labeling Balls
- poj 36876 Labeling Balls
- poj 3687 Labeling Balls
- POJ 3687 Labeling Balls
- poj-3687-Labeling Balls
- POJ 3687 Labeling Balls
- POJ 3687 Labeling Balls
- POJ 3687 Labeling Balls
- poj 3687 Labeling Balls
- POJ 3687 Labeling Balls
- poj 3687 Labeling Balls
- win7下安装ubuntu12.10
- C++中struct和class的区别和联系
- windbg调试命令7(!runaway、~)
- 服务器搭建(linux命令)
- windbg调试命令8(bp、bu、bm、bl、bc、ba、be、bd)
- POJ 3783 Balls
- LINUX下tar.xz格式文件的解压方法
- windbg调试命令9(dt、d)
- 黑马程序员-基础-网络编程
- 【计算机图形】制作能够利用鼠标拖拽实现360度旋转的3D人体模型flash文件
- 求100到200之间的所有素数
- hdu 1021 Fibonacci Again
- linux之cut
- windows 安装程序不允许安装从远程桌面连接