POJ 3783 Balls(扔鸡蛋问题——DP动态规划)
来源:互联网 发布:python for loop 编辑:程序博客网 时间:2024/04/29 07:02
传送门
Description
“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
Output
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
题目大意:
有一些鸡蛋,我们现在想知道这些鸡蛋的硬度。然后现在有一座很高很高的大楼里,我们现在要在这座大楼上测试鸡蛋的硬度。每个鸡蛋的硬度相同,鸡蛋的硬度定义为:如果鸡蛋从第
输入数据:是 T 组数据,然后第一个数 是标号
输出数据:标号
解题思路:
这是一个比较经典的
/**2016 - 08 - 03 上午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e3+5;const int MOD = 1e9+7;const double eps = 1e-7;int dp[MAXN][60];///dp[i][j]:表示在 i 层楼 还有 j 个鸡蛋的最小判断次数void Solve(int M, int N){ memset(dp, 0, sizeof(dp));///初始化 for(int i=1; i<=N; i++)///就一个鸡蛋,肯定是从第一层往上尝试的 dp[i][1] = i; for(int i=1; i<=M; i++)///就一层,肯定是 1 dp[1][i] = 1; for(int i=1; i<=N; i++) { for(int j=2; j<=M; j++) { dp[i][j] = INF;///初始化为比较大的值 for(int k=1; k<=i; k++) dp[i][j] = min(dp[i][j],max(dp[k-1][j-1],dp[i-k][j])+1); } }}int main(){ int op, N, M, T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&op,&M,&N);///N层 M个 Solve(M, N); printf("%d %d\n",op, dp[N][M]); } return 0;}
- POJ 3783 Balls(扔鸡蛋问题——DP动态规划)
- POJ 3783 Balls 动态规划
- 大楼扔鸡蛋问题(动态规划)
- 大楼扔鸡蛋问题 dp poj 3783
- POJ 3783 ——Balls 【DP】
- 动态规划实例(十一):扔鸡蛋问题
- POJ3783 Balls DP动态规划
- POJ 3783 Balls(dp)
- 大楼扔鸡蛋的问题 动态规划法
- 动态规划解抛鸡蛋(玻璃球)问题
- 楼层扔鸡蛋问题 & POJ 3783实例
- POJ——1276(动态规划,硬币问题)
- poj-3783-Balls dp/线性dp
- poj DP(动态规划)题集
- 动态规划 DP问题
- POJ 2955 DP动态规划
- poj 2192-动态规划-DP
- POJ 1163 DP 动态规划
- 毛玻璃效果
- 实现Notification上的跑马灯效果
- 进程与线程栈大小的调整(vsz 虚拟内存大小)
- scrollview中嵌套高德地图,触摸冲突解决
- 导航栏背景颜色,字体颜色
- POJ 3783 Balls(扔鸡蛋问题——DP动态规划)
- 【安卓开发】Android系统中Parcelable和Serializable的区别
- 怎么通过CorelDRAW创建斜角效果
- UVALive-7470-Easy Problemset(模拟)
- Linux各版本root本地密码破解方法
- Android常用的物理按键及其触发事件
- ListView多选操作模式详解CHOICE_MODE_MULTIPLE与CHOICE_MODE_MULTIPLE_MODAL
- SHELL 中分界符(EOF)的用法
- XML解析之DOM4J