题意: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)的更多相关文章

  1. uva 10118(DP)

    UVA 10118 题意: 有4堆糖果,每堆有n(最多40)个,有一个篮子,最多装5个糖果,我们每次只能从某一堆糖果里拿出一个糖果, 如果篮子里有两个相同的糖果,那么就可以把这两个(一对)糖果放进自己 ...

  2. Race UVA - 12034(dp+打表)

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...

  3. Cutting Sticks UVA - 10003(DP 仍有不明白的地方)

    题意:对一根长为l的木棒进行切割,给出n个切割点,每次切割的价值,等于需要切割的木头长度. 一开始理解错了,认为切割点时根据当前木条的左端点往右推算. 实际上,左端点始终是不变的一直是0,右端点一直是 ...

  4. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  5. 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)

    layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...

  6. uva 10817(数位dp)

    uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...

  7. UVA - 1347 Tour(DP + 双调旅行商问题)

    题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目 ...

  8. 紫书 习题 11-16 UVa 1669(树形dp)

    想了很久, 以为是网络流最大流, 后来建模建不出来, 无奈. 后来看了 https://blog.csdn.net/hao_zong_yin/article/details/79441180 感觉思路 ...

  9. 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环)

    layout: post title: 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环) author: "luowentaoaa" catalog: ...

随机推荐

  1. CSS水平垂直居中的方法

    原文链接:http://caibaojian.com/370.html 水平垂直居中,特别是使用在列表的时候经常会用到的,以前有需求的时候我也做过类似的代码,是使用display:table-cell ...

  2. 利用opencv训练样本分类

    参考:http://www.cnblogs.com/easymind223/archive/2012/07/03/2574826.html http://www.tuicool.com/article ...

  3. Cenots7编译Opencv3.1错误:下载ippicv,解决方案

    在centos7上安装Opencv的时候,停在了下载ippicv的地方,一直都下载不下来. ippicv是一个并行计算库,其实可以不用的. 如果不想用这个并行计算库,在做Cmake的时候用参数关闭即可 ...

  4. 微信touchmove不生效

    最近在写一个微信里面滑动切换图片的功能,发现在chrome下都正常显示,可是在微信和qq浏览器里面就是不行. 经过一番排查,发现了问题: touchmove只触发了一次. 解决方案: 在touchst ...

  5. 用PHP实现浏览器点击下载各种格式文档的方法详解【txt apk等等】

    [[注:其他文件想设置成下载文件,和下面介绍的方法一致]] 由于现在的浏览器已经可以识别txt文档格式,如果只给txt文档做一个文字链接的话,点击后只是打开一个新窗口显示txt文件的内容,并不能实现点 ...

  6. devenv.exe assert failure

    使用vs2010,创建mvc2 web application项目,编译之后,调试报错 https://www.asp.net/mvc/overview/older-versions-1/gettin ...

  7. 读《编写可维护的JavaScript》第八章总结

    第八章 避免“空比较” 我们在对传进来的参数做处理之前,肯定需要验证一下是否是我们想要的,也就是说大多数情况下,我们需要对比一下它的类型. 作者首先给了一个看起来都感觉不对的代码: var Contr ...

  8. [SAP ABAP开发技术总结]ABAP调优——代码优化

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  9. redis安装

    参考redis.io 安装步骤 下载,编译reids $ wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ tar xzf red ...

  10. MySQL 5.7 解压版安装配置

    测试环境 系统:Windows 10专业版 版本:MySQL Server 5.7.14   提纲 修改配置文件 初始化 安装服务.启动服务 修改root密码   步骤 1.解压安装包 在MySQL官 ...