题面

\(n\) 楼 \(m\) 个鸡蛋,从 \(k\) 楼及以上扔下去会碎,不能再测试 .

问至少需要扔几次确定 \(k\) .

\(n\le 10^{18}\),\(m\le 64\) .

题解

令 \(dp_{i,j}\) 表示 \(i\) 个鸡蛋丢 \(j\) 次能确定的最高楼层(其实是 OEIS A180975 / A131251) .

显然最后一个走第 \(k\) 步的时候,和上一步之间的空隙不能超过 \(dp_{i-1,j-k}+1\),不然中间无法判定 .

于是

\[\begin{aligned}dp_{i,j}&=\sum_{k=1}^{j}(dp_{i-1,j-k}+1)\\&=j+\sum_{k=0}^{j-1}dp_{i-1,k}\\&=dp_{i-1,j}+dp_{i-1,j-1}+1\end{aligned}
\]

即 \(dp_{i,j}=dp_{i-1,j}+dp_{i-1,j-1}+1\) .

我们转成一个二项式系数的形式:

\[dp_{i,j}=\sum_{p=0}^{j-1}\sum_{q=0}^{i-1}\dbinom pq
\]
过程(artalter)

令 \(g_{i,j}=dp_{i+1,j}-dp_{i,j}\) .

\[\begin{aligned}g_{i,j}&=(1+dp_{i,j}+dp_{i,j-1})-(1+dp_{i-1,j}+dp_{i-1,j-1})\\&=dp_{i,j}+dp_{i,j-1}-dp_{i-1,j}-dp_{i-1,j-1}\\&=(dp_{i,j}-dp_{i-1,j})+(dp_{i,j-1}-dp_{i-1,j-1})\\&=g_{i-1,j}+g_{i-1,j-1}\end{aligned}
\]

妈呀这不是组合数吗?

于是就可以轻易建立 \(dp\) 到 \(g\) 的联系,从而推出式子了 .

随便推推

\[\begin{aligned}dp_{i,j}&=\sum_{p=0}^{j-1}\sum_{q=0}^{i-1}\dbinom pq\\&=\sum_{q=0}^{i-1}\sum_{p=0}^{j-1}\dbinom pq\\&=\sum_{q=0}^{i-1}\dbinom {j}{q+1}\end{aligned}
\]

然后随便线性做了 .

外面套一个二分就完了 .

时间复杂度 \(O(m\log n)\) .


细节:\(dp\) 增长很快,大于 \(n\) 直接丢掉,用 double 注意浮点误差

代码

using namespace std;
typedef long long ll;
typedef __int128 i128;
const int N = 111;
const double LIM = 1e18;
ll n, k;
inline bool check(ll x)
{
i128 now=1, ans=0;
for (int l=0; l<k; l++)
{
if (1.0*now*(x-l)/(l+1) > LIM) return true;
now = now*(x-l)/(l+1); ans += now;
if (ans >= n) return true;
} return ans >= n;
}
int main()
{
int T; scanf("%d", &T);
while (T--)
{
scanf("%lld%lld", &n, &k);
ll l=0, r=n, ans=-1;
while (l <= r)
{
ll mid = (l + r) >> 1;
if (check(mid)){r = mid-1; ans = mid;}
else l = mid+1;
}
printf("%lld\n", ans);
}
return 0;
}

膜 社论(egg drop)的更多相关文章

  1. [Swift]LeetCode887. 鸡蛋掉落 | Super Egg Drop

    You are given K eggs, and you have access to a building with N floors from 1 to N. Each egg is ident ...

  2. 887. Super Egg Drop

    You are given K eggs, and you have access to a building with N floors from 1 to N. Each egg is ident ...

  3. [LeetCode] 887. Super Egg Drop 超级鸡蛋掉落

    You are given K eggs, and you have access to a building with N floors from 1 to N.  Each egg is iden ...

  4. 【LeetCode】887. Super Egg Drop 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 参考资料 日期 题目地址:https://leetc ...

  5. Coursera Algorithms week1 算法分析 练习测验: Egg drop 扔鸡蛋问题

    题目原文: Suppose that you have an n-story building (with floors 1 through n) and plenty of eggs. An egg ...

  6. Leetcode 887 Super Egg Drop(扔鸡蛋) DP

    这是经典的扔鸡蛋的题目. 同事说以前在uva上见过,不过是扔气球.题意如下: 题意: 你有K个鸡蛋,在一栋N层高的建筑上,被要求测试鸡蛋最少在哪一层正好被摔坏. 你只能用没摔坏的鸡蛋测试.如果一个鸡蛋 ...

  7. LeetCode 887. Super Egg Drop

    题目链接:https://leetcode.com/problems/super-egg-drop/ 题意:给你K个鸡蛋以及一栋N层楼的建筑,已知存在某一个楼层F(0<=F<=N),在不高 ...

  8. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

  9. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

随机推荐

  1. 论文解读(SimGRACE)《SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation》

    论文信息 论文标题:SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation论文作者: ...

  2. jQuery前端第三方框架

    计时器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  3. nodejs + koa + typescript 集成和自动重启

    版本说明 Node.js: 16.13.1 全局安装 TypeScript yarn global add typescript 创建项目 创建如下目录结构 project ├── src │ └── ...

  4. 类型安全的 Go HTTP 请求

    前言 对 Gopher 来说,虽然我们基本都是在写代码让别人来请求,但是有时候,我们也需要去请求第三方提供的 RESTful 接口,这个时候,我们才能感受到前端同学拼接 HTTP 请求参数的痛苦. 比 ...

  5. Thymeleaf 公共css,js提取及自有css,js导入

    https://www.jianshu.com/p/2102fa4772ba

  6. CNN Training Loop Refactoring Simultaneous Hyperameter Testing

    上例中, 尝试两个不同的值 为此: alt+shift可以有多个光标,再jupyter notebook中. alt+d,alt+shift,ctrl+鼠标左键多点几个,都可以同时选择多个目标,并进行 ...

  7. Jmeter(五十三) - 从入门到精通高级篇 - 懒人教你在Linux系统中安装Jmeter(详解教程)

    1.简介 我们绝大多数使用的都是Windows操作系统,因此在Windows系统上安装JMeter已经成了家常便饭,而且安装也相对简单,但是服务器为了安全.灵活小巧,特别是前几年的勒索病毒,现在绝大多 ...

  8. Acwing787.归并排序

    Acwing787.归并排序 归并模板 归并排序,合二为一 题目链接:Acwing787.归并排序 #include<iostream> using namespace std; cons ...

  9. 3.shell脚本循环试题

    shell脚本循环试题 1.计算从1到100所有整数的和 #!/bin/bash a=0 for i in {1..100} #1到100 #每次循环变量i的值也为循环次数 do a=$[ $a + ...

  10. 一分钟入门 Babel(下一代 JavaScript 语法的编译器)

    简单来说把 JavaScript 中 es2015/2016/2017/2046 的新语法转化为 es5,让低端运行环境(如浏览器和 node )能够认识并执行.严格来说,babel 也可以转化为更低 ...