题意: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. 最牛B的编码套路 - 呦呦鹿鸣 - 博客频道 - CSDN.NET

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  2. [课程设计]Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面)

    Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队 ...

  3. linux下打开、关闭tomcat,实时查看tomcat运行日志

    启动:一般是执行sh tomcat/bin/startup.sh 停止:一般是执行sh tomcat/bin/shutdown.sh脚本命令 查看:执行ps -ef |grep tomcat 输出如下 ...

  4. ML-线性回归

    记样本数目为$m$,样本点$i$用$(x^{(i)}, y^{(i)})$表示,其中 $x^{(i)}=\begin{pmatrix}x_1^{(i)}\\ x_2^{(i)}\\ ...\\x_n^ ...

  5. Client Window坐标 RECT相关函数

    GetClientRect(HWND, RECT*) ---得到窗口的客户区大小,left,top总是0,bottom是客户区高度,right是客户区宽度 GetWindowRect(HWND, RE ...

  6. Linux术语全称

    bin = BINaries (binary) /dev = devices /etc = ETCetera etcetera附加的人, 附加物, 以及其它, 等等 /lib = LIBrary /p ...

  7. js 练习

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="req_form.aspx.cs ...

  8. mybatis批量插入返回主键问题

    今天整合mybatis时候用到返回主键问题,批量插入总是返回不了主键还报错. 记录入下: pom版本: <mybatis.version>3.2.6</mybatis.version ...

  9. DEV GridControl小结

    1. 如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 2. 如何新增一条记录 (1).gridView.Ad ...

  10. 最小化安装的CentOS7挂载ntfs格式的U盘

    准备从系统中拷贝一些文件到U盘,插上U盘. 一.获得U盘的设备识别符 fdisk -l 啊哈,我看到了,是/dev/sdb1 二.熟练的挂载 mount /dev/sdb1 /mnt/usb Duan ...