非常详细的题解:戳这里

例题:poj-3783 Balls

Balls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1151   Accepted: 748

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

附ac代码:

dp法一:

 1 #include<iostream>
2 #include <cstdio>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #include <string>
7 typedef long long ll;
8 using namespace std;
9 const int maxn = 1e3 + 10;
10 const int inf = 0x3f3f3f3f;
11 int a[maxn], b[maxn], c[maxn];
12 int dp[111][maxn];
13 int main()
14 {
15 int n, m;
16 // scanf("%d %d", &n, &m);
17 for(int j = 1; j <= 1005; ++j)
18 {
19 dp[1][j] = j;
20 }
21 for(int i = 1; i <= 55; ++i)
22 {
23 dp[i][1] = 1;
24 }
25 for(int i = 2; i <= 55; ++i)
26 {
27 for(int j = 1; j <= 1005; ++j)
28 {
29 dp[i][j] = inf;
30 for(int k = 1; k <= j; ++k)
31 dp[i][j] = min(dp[i][j],max(dp[i - 1][k - 1], dp[i][j - k]) + 1);
32 }
33 }
34 // int ans = 111;
35 int t;
36 int cas;
37 scanf("%d", &t);
38 while(t--) {
39 scanf("%d %d %d", &cas, &n, &m);
40 printf("%d %d\n", cas, dp[n][m]);
41 }
42
43 return 0;
44 }

dp法二:

蓝桥杯-摔手机问题【dp】的更多相关文章

  1. 蓝桥杯 传球游戏(dp)

    Description 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏.游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始 ...

  2. 蓝桥杯---波动数列(dp)(背包)(待解决)

    问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. 栋栋对这种数列很好奇,他想知道长度为 n 和为 s 而且后一项总是比前一项增加a或者减 ...

  3. 2018年第九届蓝桥杯B组第四题:摔手机题解

    摔手机 摔手机 动态规划  在蓝桥杯的时候遇到一次 当时没有做对  看了题解也没明白  如今再次遇到这个类似的题目 于是拿出来补补吧 摔手机题目如下: 星球的居民脾气不太好,但好在他们生气的时候唯一的 ...

  4. 蓝桥杯——测试次数·摔手机(2018JavaB组第4题,17分)

    x星球的居民脾气不太好,但好在他们生气的时候唯一的异常举动是:摔手机. 各大厂商也就纷纷推出各种耐摔型手机.x星球的质监局规定了手机必须经过耐摔测试,并且评定出一个耐摔指数来,之后才允许上市流通. x ...

  5. 蓝桥杯历届试题 地宫取宝 dp or 记忆化搜索

    问题描述 X 国王有一个地宫宝库.是 n x m 个格子的矩阵.每个格子放一件宝贝.每个宝贝贴着价值标签. 地宫的入口在左上角,出口在右下角. 小明被带到地宫的入口,国王要求他只能向右或向下行走. 走 ...

  6. 树形dp|无根树转有根树|2015年蓝桥杯生命之树

    2015年蓝桥杯第十题--生命之树(无根树dfs) ①暴力解法:枚举子集(选点) + dfs判断连通性(题目要求连通)满足上面两个条件下找出最大值权值和 ②dfs无根树转有根树,递归找最优 先学习无根 ...

  7. 梳理一下最近准备蓝桥杯时学习DP问题的想法

    学习时间不长,记录的只是学习过程的思路和想法,不能保证正确,代码可以在acwing上AC. 01背包问题: 1.首先是简单的01背包问题 2.先确定状态,f[i][j]表示有第i件物品,时间为j的最大 ...

  8. 2021蓝桥杯省赛B组(C/C++)E.路径【最短路DP】

    2021蓝桥杯省赛B组题目(C/C++)E.路径 最短路径, 因为变化情况比较多, 所以开始想的是深搜, 但是太慢了, 跑不出来, 后来就想着优化一下, 有的地方到另一个地方可能会考虑很多遍, 于是考 ...

  9. 2021蓝桥杯省赛C++A组试题E 回路计数 状态压缩DP详细版

    2021蓝桥杯省赛C++A组试题E 回路计数 状态压缩DP 题目描述 蓝桥学院由21栋教学楼组成,教学楼编号1到21.对于两栋教学楼a和b,当a和b互质时,a和b之间有一条走廊直接相连,两个方向皆可通 ...

随机推荐

  1. 使用.net中的API网关模式封装微服务

    在本文中,我们将了解如何使用API网关模式来封装微服务并抽象出底层实现细节,从而允许使用者拥有进入我们系统的一致入口点. 为了构建和测试我们的应用程序,我们需要: 1.Visual Studio 20 ...

  2. Description Resource Path Location Type Failure to transfer org.apache.maven.plugins:maven-surefire-

    url:https://www.pianshen.com/article/8003307916/ Description Resource Path Location Type Failure to ...

  3. 入门OJ:扫雪

    扫雪1 题目描述 大雪履盖了整个城市,市政府要求冬季服务部门尽快将一些街道(列在一份清单中)的积雪清除掉以恢复交通,整个城市由许多交叉路口和街道构成,当然任意两个交叉路口都是直接或间接连通的,清单给出 ...

  4. Ubuntu创建桌面图标

    以火狐为例 创建"~/.local/share/applications/firefox_dev.desktop"文件, 文件内容为: [Desktop Entry] Name=F ...

  5. QTextEdit字符串的高亮显示问题

    20130222 鬼猫猫 整理 http://www.cnblogs.com/muyr/ 解决方法的原始地址 http://www.qtcn.org/bbs/read.php?tid=20335 背景 ...

  6. GlusterFS分布式存储系统复制集更换故障Brick操作记录

    场景: GlusterFS 3节点的复制集,由于磁盘故障,其中一个复制集需要重装系统,所以需要重装glusterfs并将该节点加入glusterfs集群 一. 安装GlusterFS 首先在重装系统节 ...

  7. Ubuntu 能ping通DNS 地址 无法解析域名

    ping通qq百度都行,唯独谷歌不行, 主机能够ping通google的dns服务器地址 8.8.8.8,却无法解析域名   $ ping www.google.co.uk ping: unknown ...

  8. 基于Vue的npm组件库

    前言(*❦ω❦) 思维导图可能有点高糊,有点太大了,项目和导图文件放到github或giteee上,这个思维导图也是我文章的架构,思维导图是用FeHelper插件生成的,这个是一款开源chrome插件 ...

  9. Bitter.Core系列六:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例 DataTable 模型转换

    当我们查询之前,我们先构造一个查询对象的输出DTO.如下图代码: public class TScoreSearchDto { /// <summary> /// 分数 /// </ ...

  10. (Sql Server)存储过程(转载)

    SQL Server 存储过程 Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这 ...