uva 10934(dp)
题意:k个水球,现在在一个n层建筑物上,水球可能在某一层层以上扔下去会破掉,现在求一个最少的次数使得用这k个水球能确定出哪一层。
思路:假设有i个小球,还可以实验j次时,第一个小球从x处扔下去,如果破了,那么可以确定答案肯定在x之下找,剩下i-1个小球和j-1次实验,可以在x之下确定出最高层数,那么x-1就是这最高层数(试想如果x-1 > 最高层数,那么中间可能有一些层数就无法确定了)所以x = f[i - 1][j - 1] + 1;
然后在考虑,如果这个小球在x位置没破,那么就往上找,这时候有i个小球,j-1次,用这些去往上确定层数为f[i][j - 1],那么往下和往上能确定的层数加起来就是总的能确定的层数
f[i][j] = f[i - 1][j - 1] + 1 + f[i - 1][j];
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define sfi2(n, m) scanf("%d%d", &n, &m)
#define pfi2(n, m) printf("%d %d\n", n, m)
#define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
#define MAXN 105
const int INF = 0x3f3f3f3f;
#define ull unsigned long long
ull dp[MAXN][];
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std; typedef long long int64; int64 f[][]; inline void init() {
memset(f, , sizeof(f));
for (int i = ; i < ; ++i) {
for (int j = ; j < ; ++j) {
f[i][j] = f[i][j-] + f[i-][j-] + ;
}
}
}
int main(){ init();
int k;
int64 n; while (~scanf("%d%lld", &k, &n) && k) {
k = min(, k);
bool ok = false;
for (int i = ; i <= ; ++i) {
if (f[k][i] >= n) {
printf("%d\n", i);
ok = true;
break;
}
}
if (!ok) puts("More than 63 trials needed.");
}
return ;
}
uva 10934(dp)的更多相关文章
- uva 10118(DP)
UVA 10118 题意: 有4堆糖果,每堆有n(最多40)个,有一个篮子,最多装5个糖果,我们每次只能从某一堆糖果里拿出一个糖果, 如果篮子里有两个相同的糖果,那么就可以把这两个(一对)糖果放进自己 ...
- Race UVA - 12034(dp+打表)
Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...
- Cutting Sticks UVA - 10003(DP 仍有不明白的地方)
题意:对一根长为l的木棒进行切割,给出n个切割点,每次切割的价值,等于需要切割的木头长度. 一开始理解错了,认为切割点时根据当前木条的左端点往右推算. 实际上,左端点始终是不变的一直是0,右端点一直是 ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- uva 10817(数位dp)
uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...
- UVA - 1347 Tour(DP + 双调旅行商问题)
题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目 ...
- 紫书 习题 11-16 UVa 1669(树形dp)
想了很久, 以为是网络流最大流, 后来建模建不出来, 无奈. 后来看了 https://blog.csdn.net/hao_zong_yin/article/details/79441180 感觉思路 ...
- 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环)
layout: post title: 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环) author: "luowentaoaa" catalog: ...
随机推荐
- java ide 导出可运行jar包
常常会用到写个jar搬到其他地方运行的情况,这里做个笔记记录下如何利用eclipse或者idea导出jar. 导出jar包最好的方式个人认为是把依赖的包都打包进目标jar,这样一个jar可以很happ ...
- 【转】Tomcat版本是32位、64位问题
转载地址:http://www.cnblogs.com/greensleeves/p/3168541.html 最近遇到一个Tomcat windows安装版本是32位还是64位问题.由于一系列原因, ...
- java反射类内容获取
private void DtoReflect(Object obj, MqDto mqDto) throws Exception { Map map = getMap(mqDto); if(obj= ...
- python 学习笔记十七 django深入学习二 form,models
表单 GET 和 POST 处理表单时候只会用到GET 和 POST 方法. Django 的登录表单使用POST 方法,在这个方法中浏览器组合表单数据.对它们进行编码以用于传输.将它们发送到服务器然 ...
- android HAL 教程(含实例)
http://www.cnblogs.com/armlinux/archive/2012/01/14/2396768.html Android Hal 分析 ...
- 5.对与表与表之间的关系,efcore是如何处理的
public class Account { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Accoun ...
- yum安装命令的使用方法
yum安装常用软件的命令 #yum check-update #yum remove 软件包名 #yum install 软件包名 #yum update 软件包名 yum命令常见使用方法 yum - ...
- python 类
封装 继承(可多继承) 多态 经典类:深度优先 新式类(继承object):广度优先 模板: class <类名>(object): <语句> class <类名> ...
- Linux常用命令及shell脚本
一. 用户管理(添加用户.切换用户.删除用户) ~ ...
- 读《编写可维护的JavaScript》第八章总结
第八章 避免“空比较” 我们在对传进来的参数做处理之前,肯定需要验证一下是否是我们想要的,也就是说大多数情况下,我们需要对比一下它的类型. 作者首先给了一个看起来都感觉不对的代码: var Contr ...