膜 社论(egg drop)
题面
\(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\),不然中间无法判定 .
于是
\]
即 \(dp_{i,j}=dp_{i-1,j}+dp_{i-1,j-1}+1\) .
我们转成一个二项式系数的形式:
\]
过程(artalter)
令 \(g_{i,j}=dp_{i+1,j}-dp_{i,j}\) .
则
\]
妈呀这不是组合数吗?
于是就可以轻易建立 \(dp\) 到 \(g\) 的联系,从而推出式子了 .
随便推推
\]
然后随便线性做了 .
外面套一个二分就完了 .
时间复杂度 \(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)的更多相关文章
- [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 ...
- 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 ...
- [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 ...
- 【LeetCode】887. Super Egg Drop 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 参考资料 日期 题目地址:https://leetc ...
- Coursera Algorithms week1 算法分析 练习测验: Egg drop 扔鸡蛋问题
题目原文: Suppose that you have an n-story building (with floors 1 through n) and plenty of eggs. An egg ...
- Leetcode 887 Super Egg Drop(扔鸡蛋) DP
这是经典的扔鸡蛋的题目. 同事说以前在uva上见过,不过是扔气球.题意如下: 题意: 你有K个鸡蛋,在一栋N层高的建筑上,被要求测试鸡蛋最少在哪一层正好被摔坏. 你只能用没摔坏的鸡蛋测试.如果一个鸡蛋 ...
- LeetCode 887. Super Egg Drop
题目链接:https://leetcode.com/problems/super-egg-drop/ 题意:给你K个鸡蛋以及一栋N层楼的建筑,已知存在某一个楼层F(0<=F<=N),在不高 ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
随机推荐
- Python-100-Days-master
跟着python100学习一下 100以内的素数 # 输出100以内的所有素数 # 想法:从1到100遍历,假设得到了i=17,那么此时从1到9遍历,如果找到了一个数用17能除尽则跳出循环 # 如果找 ...
- 一个关于 useState 的误解
一个关于 useState 的误解 本文写于 2020 年 11 月 17 日 前两天有人问了我一个问题,他有一段这样的代码: function App() { const [n, setN] = u ...
- mybatis 查询返回的类型中字段类型为 List<xx>
基本类型数组 mapper.xml <resultMap id="xxDtoResultMap" type="com.xx.xxDto"> < ...
- Spring 源码(14)Spring Bean 的创建过程(6)对象的提前暴露
知识回顾 解析完Bean信息的合并,可以知道Spring在实例化Bean之后,属性填充前,对Bean进行了Bean的合并操作,这里的操作主要做了对Bean对象标记了@Autowired.@Value. ...
- SPPNet(特征金字塔池化)学习笔记
SPPNet paper:Spatial pyramid pooling in deep convolutional networks for visual recognition code 首先介绍 ...
- Random 中的Seed
C#中使用随机数 看下例 当Random的种子是0时 生成的随机数列表是一样的 也就是说当seed 一样时 审查的随机数时一样的 Random的无参实例默认 种子 时当前时间 如果要确保生成的随机数不 ...
- 最大流&最小割&费用流模版
好久都没有搞博客了.想认真写又要准备文化课期末了. ISAP 流程: 原理就是dfs找增广路. 最基础的建反向边以便反悔就不说了. 但是记录一个dep(dis)表示层数,一开始BFS(从t开始,dis ...
- 关于spring整合mybatis
第一步导入依赖 <dependencies> <dependency> <groupId>org.mybatis</groupId> <artif ...
- 使用kubeseal加密和管理k8s集群的secret
使用kubeseal加密和管理k8s集群的secret 在k8s的管理过程中,像secret这种资源并不好维护,kubeseal提供了一种相对简单的方式来对原始secret资源进行加密,并通过控制器进 ...
- 想学设计模式、想搞架构设计,先学学UML系统建模吧您
UML系统建模 1 概述 1.1 课程概述 汇集UML及其相关的一些话题 回顾UML相关的符号与概念 以电商订单相关业务为例,借助UML完成系统建模 将UML变成提升建模效率,表达架构思想的工具 1. ...