Dropping water balloons
题意:
给你k个水球n层楼(n很大) 现在做实验在楼上向下丢水球,若水球没破可以重新丢,求把所有水球弄破的最小试验次数。
分析:
开始完全没思路啊。从正面求没法做不会表示状态,做实验是只能从第一层,一层层向上试,应该dp[i][j]有i个水球,做j次实验能达到的最高楼层数,考虑到求破没破的情况若球破了,可以向下走,没破向上走dp[i][j]=dp[i-1][j-1]+1+dp[i][j-1];
最后取第一大于n的就是答案
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int k;
ll n,dp[][];
void solve(){
memset(dp,,sizeof(dp));
for(int i=;i<;++i)
for(int j=;j<;++j)
dp[i][j]=dp[i-][j-]++dp[i][j-];
int f=;
k=min(k,);
for(int i=;i<;++i){
if(dp[k][i]>=n){
f=;
printf("%d\n",i);
break;
}
}
if(!f)printf("More than 63 trials needed.\n");
}
int main()
{
while(~scanf("%d%lld",&k,&n)&&k){
solve();
}
return ;
}
Dropping water balloons的更多相关文章
- UVa 10934 Dropping water balloons:dp(递推)
题目链接:https://vjudge.net/problem/27377/origin 题意: 有一栋n层高的楼,并给你k个水球.在一定高度及以上将水球扔下,水球会摔破:在这个高度以下扔,水球不会摔 ...
- uva 10934 Dropping water balloons(转载)
本文转载自http://blog.csdn.net/shuangde800/article/details/11273123 题意 你有k个一模一样的水球,在一个n层楼的建筑物上进行测试,你想知道水球 ...
- uva10934 Dropping water balloons
//好久没做题 一直没状态 然后刷了个水题玩玩 //寒假集训和校赛都做到了类似的题目 然而当时并不会 (其实现在也不会 题意:有k个气球和一个n层高的楼,气球有硬度,在某曾会恰好摔碎,问至少多少次实验 ...
- Dropping water balloons (入门dp)
2017-08-12 18:36:24 writer:pprp 最近刚刚接触动态规划,感觉状态的查找和转移自己很难想到,都是面向题解编程,但是一开始都是这样了,只有相信我可以独立自己解决动态规划这类问 ...
- UVA - 10934 Dropping water balloons (dp,逆向思维)
题目链接 题目大意:给你n个规格一样的气球和一栋大楼的高度,求最少试验几次能测出气球最高在哪一层掉下来不破. 如果这道题想用(dp[i][j]=用i个气球测出j高度的楼需要几次)来作为状态的话,那你就 ...
- uva 10934 Dropping water balloons
你有k个一模一样的水球,在一个n层楼的建筑物上进行测试,你想知道水球最低从几层楼往下丢可以让水球破掉.由于你很懒,所以你想要丢最少次水球来测出水球刚好破掉的最低楼层.(在最糟情况下,水球在顶楼也不会破 ...
- UVa 10934 DP Dropping water balloons
首先想一下特殊情况,如果只有一个气球,我们要确定高度只能从下往上一层一层地测试,因为如果气球一旦爆了,便无法测出气球的硬度. 如果气球有无数个,那么就可以用二分的方法来确定. 一般地,用d(i, j) ...
- 10934 - Dropping water balloons(DP)
这道题的思路非常难想. 问你须要的最少实验次数,这是非常难求解的.并且我们知道的条件仅仅有三个.k.n.实验次数 . 所以我们最好还是改变思路,转而求最高所能确定的楼层数 . 那么用d[i][j]表 ...
- 【Uva 10934】Dropping water balloons
[Link]: [Description] 等价题意: 某人在1..n内选一个数x; 然后让你去猜; 你可以问他是不是在哪个范围里; 每次会告诉你YES或者NO; 问你在最坏的情况下猜出答案需要猜多少 ...
随机推荐
- Pycharm中的实用功能(网上看到的,感觉还不错)
实时比较 PyCharm 对一个文件里你做的改动保持实时的跟踪,通过在编辑器的左侧栏显示一个蓝色的标记.这一点非常方便,我之前一直是在Eclipse里面用命令“Compare against HEAD ...
- 关于dynamic_cast
http://www.groad.net/bbs/read.php?tid-5476.html dynamic_cast 进行运行时强制转换.如果在执行时转换非法,则会转换失败.dynamic_cas ...
- Error: The VPN client agent was unable to create the interprocess communication depot.
当安装Cisco AnyConnect VPN Client出现The VPN client agent was unable to create the interprocess communica ...
- Python批量读取人脸图片与数据互相转换
读取部分结果 程序 # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from PIL import ...
- [topcoder] EllysNumberGuessing
http://community.topcoder.com/stat?c=problem_statement&pm=12975 简单题 #include <cstdlib> #in ...
- compiler 学习
一款强大的编译器LLVM:http://llvm.org/docs/GettingStarted.html#layout http://llvm.org/docs/LangRef.html http: ...
- React-用ImmutableJS提高性能
一.需求 1.子组件有更新时,只重新渲染有变化的子组件,而不是全部 二.ImmutableJS原理 三.代码 1.CheckboxWithLabel.jsx var React = require(' ...
- 74. Search a 2D Matrix
题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f ...
- 50. Pow(x, n)
题目: Implement pow(x, n). 链接: http://leetcode.com/problems/powx-n/ 题解: 使用二分法求实数幂,假如不建立临时变量halfPow,直接r ...
- JVM学习笔记(四)------内存调优
首先需要注意的是在对JVM内存调优的时候不能只看操作系统级别Java进程所占用的内存,这个数值不能准确的反应堆内存的真实占用情况,因为GC过后这个值是不会变化的,因此内存调优的时候要更多地使用JDK提 ...