Balls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1196   Accepted: 783

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

 
 
#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的更多相关文章

  1. poj 3783 Balls 动态规划 100层楼投鸡蛋问题

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098409.html 题目链接:poj 3783 Balls 动态规划 100层楼投鸡蛋问题 ...

  2. POJ 3783 Balls --扔鸡蛋问题 经典DP

    题目链接 这个问题是谷歌面试题的加强版,面试题问的是100层楼2个鸡蛋最坏扔多少次:传送门. 下面我们来研究下这个题,B个鸡蛋M层楼扔多少次. 题意:给定B (B <= 50) 个一样的球,从 ...

  3. Balls(poj 3783)

    The classic Two Glass Balls brain-teaser is often posed as: “Given two identical glass spheres, you ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. python入门之集合set

    集合(无序不重复) 创建 s = {} s = set() 转换 s = set(li) 方法 s.add("chy") #添加元素 s.clear() #清除元素 a = s.d ...

  2. 使用express+mongoDB搭建多人博客 学习(5)权限控制

    修改index.js如下: var express = require('express'); var router = express.Router(); var crypto=require('c ...

  3. 牛客网Java刷题知识点之线程的几种可用状态(新建、可运行、运行、阻塞、死亡)

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=13 ...

  4. nopCommerce - asp.net开源商城

    nopcommerce官网 http://nopcommerce.codeplex.com/ nopCommerce is a open source e-commerce solution that ...

  5. 关于.NET .cs后台提示并进行页面跳转代码

    在后台.CS页面中植入下面代码 string url = "<script>alert('xxx');window.location.href='"xxx.html&q ...

  6. 自定义消息中如果需要定义WPARAM和LPARAM,该怎么使用和分配?

    写Windows程序不可避免要使用自定义的消息,也就是从WM_USER开始定义的消息.在定义一个消息后,往往我们还要定义针对该消息的WPARAM甚至是LPARAM.WPARAM和LPARAM是什么,可 ...

  7. MFC双缓冲解决图象闪烁[转]

    转载网上找到的一篇双缓冲的文章,很好用.http://www.cnblogs.com/piggger/archive/2009/05/02/1447917.html__________________ ...

  8. 对话框窗口最大化盖住任务栏问题!OnGetMinMaxInfo,WM_GETMINMAXINFO

    http://hi.baidu.com/csacer/item/37cd6ac2dec18d360831c6a7 在写程序时,如果包含了标题栏,但是没有包含最大化按钮或者最小话按钮,那么人工用Show ...

  9. Linux shell例子

    #!/bin/bash read -p "input a dight:"echo $REPLY DATE=`date`echo "DATE is ${DATE}" ...

  10. ADO1

    1. 新建Web窗体 客户端控件:html控件 服务器控件:用的比较少 2. 数据库连接 protected void btnLogin_Click(object sender, EventArgs ...