poj 3783
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1196 | Accepted: 783 |
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
Source
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
using namespace std;
#define ll long long
#define N 1000009
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define lowbit(x) x&(-x)
#define inf 100000
int t,a,b,m;
int dp[][];
/*
dp[i][j]:i层楼,J个球在最坏的情况下需要的次数
枚举前面的k : 1 ~ i
没碎 dp[i][j]=dp[i-k][j]+1//还有i-k层楼,下面的楼肯定不需要了,还有j个球
碎了 dp[i][j]=dp[k-1][j-1]+1//往下k-1层,上面的楼肯定不用查了,还有j-1个球
dp[i][j]=min(dp[i][j],max(dp[i-k][j],dp[k-1][j-1])+1);//+1因为 k 层楼需要一次
*/
void init(){
gep(i,,){
gep(j,,){
dp[i][j]=inf;
}
}
gep(i,,) dp[][i]=;
//从1开始
gep(i,,){
gep(j,,){
gep(k,,i){
dp[i][j]=min(dp[i][j],max(dp[i-k][j],dp[k-][j-])+);
}
}
}
}
int main()
{
init();
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&a,&b,&m);
printf("%d %d\n",a,dp[m][b]);
}
return ;
}
poj 3783的更多相关文章
- poj 3783 Balls 动态规划 100层楼投鸡蛋问题
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098409.html 题目链接:poj 3783 Balls 动态规划 100层楼投鸡蛋问题 ...
- POJ 3783 Balls --扔鸡蛋问题 经典DP
题目链接 这个问题是谷歌面试题的加强版,面试题问的是100层楼2个鸡蛋最坏扔多少次:传送门. 下面我们来研究下这个题,B个鸡蛋M层楼扔多少次. 题意:给定B (B <= 50) 个一样的球,从 ...
- Balls(poj 3783)
The classic Two Glass Balls brain-teaser is often posed as: “Given two identical glass spheres, you ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- substring()和substr()的使用以及区别
在JavaScript中,通常会用到截取,那所谓截取呢,其实就是要获得被截取元素的某个位置到某个位置的内容,那么JS给我提供了substring和substr这两种方法: 这两种截取的方式有什么区别呢 ...
- Linux下环境搭建(三)——jmeter+ant配置
在linux环境下,使用jmeter做接口自动化,做好了前两步的准备工作后,怎能少了主角jmeter+ant了,今天就来说下jmeter+ant的配置方式. jmeter配置 jmeter下载地址:h ...
- vue使用echarts可视化图形插件
1.安装echarts: cnpm/npm i echarts -S 2.main.js中 import echarts from 'echart' Vue.prototype.$echa ...
- mac下只遍历目录不遍历文件
install brew install tree 命令 tree -d
- JS与JQ 获取页面元素值的方法和差异对比
获取浏览器高度和宽度 document.documentElement.clientWidth ==> 浏览器可见区域宽度 document.documentElement.clientHeig ...
- 在idea下创建maven
之前一直用eclipse,现在要用idea写一个安装过程玩玩 一:New Project 二:选择maven,在project SDK上选择你安装的jdk,默认安装在c:/Program Files ...
- python基础一 day10(1)
要背的:
- MAC环境Android SDK环境变量配置
一.材料 1.Mac设备1台: 2.下载并更新android SDK:示列中sdk存放路径为/Users/gametest/Library/Android/sdk 二.操作步骤 1.启动Termina ...
- java在线聊天项目 客户端登陆窗口LoginDialog的注册用户功能 修改注册逻辑 增空用户名密码的反馈 增加showMessageDialog()提示框
LoginDialog类的代码修改如下: package com.swift.frame; import java.awt.EventQueue; import java.awt.event.Acti ...
- iOS 高效 Mac 配置
https://testerhome.com/topics/3045 https://support.apple.com/zh-cn/HT201236