CF1153F Serval and Bonus Problem FFT
CF1153F Serval and Bonus Problem
官方的解法是\(O(n ^ 2)\)的,这里给出一个\(O(n \log n)\)的做法。
首先对于长度为\(l\)的线段,显然它的答案就是长度为\(1\)的线段的答案\(\times l\),这样做只是为了方便计算。
考虑对于数轴上区间\([0,1]\)内任意一个点\(x\),它被一条随机线段覆盖的概率是多少:线段的两个端点都在它左边的概率是\(x ^ 2\)、都在它右边的概率是\((1 - x) ^ 2\),那么它被覆盖的概率即为\(p(x) = 1 - x^2 - (1 - x) ^ 2 = 2 x (1 - x)\)。
那么他被\(\ge k\)条线段覆盖的概率为\(f(x) = \sum \limits _{i = k} ^ n \binom{n}{i} p(x) ^ i (1 - p(x)) ^ {n - i}\)。
根据定积分的定义就得到区间\([0,1]\)内被\(\ge k\)条线段覆盖的长度期望为\(\int _{0} ^{1} f(x) \mathrm{d} x\)。
现在我们的问题就是怎么算这个东西了:
\]
推到这里,就可以把积分去掉了,这是一个Beta Function的形式:记结论吧
\]
代入得:
\]
令\(t = i + j\),\(f[i] = \frac {1} {i}\),\(g[j] = \frac {(-1) ^ j} {j !}\),\(h[t] = \frac{2^t (t !) ^ 2} {(2 t + 1) ! (n - t) !}\),考虑枚举\(t\):
\]
这后面就是一个非常显然的卷积式子了,直接FFT即可。
答案记得\(\times l\)。
//written by newbiechd
#include <cstdio>
#include <cctype>
#include <algorithm>
#define BUF 1000000
using namespace std;
const int N = 100003, yyb = 998244353, Gg = 3, Gi = 332748118;
char buf[BUF], *p1, *p2;
inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int rd() {
register int f = 0;
register char c;
while (!isdigit(c = gc())) {}
do
f = f * 10 + (c ^ 48);
while (isdigit(c = gc()));
return f;
}
int rev[N], G[2][N];
inline int power(int x, int y) {
register int o = 1;
for (; y; y >>= 1, x = 1ll * x * x % yyb)
if (y & 1)
o = 1ll * o * x % yyb;
return o;
}
inline void ntt(int *f, int len, int opt) {
register int i, j, k, x, y, p, q;
for (i = 1; i < len; ++i)
if (i < rev[i])
swap(f[i], f[rev[i]]);
for (i = 1; i < len; i <<= 1) {
p = G[opt][i];
for (j = 0; j < len; j += i << 1)
for (k = 0, q = 1; k < i; ++k, q = 1ll * p * q % yyb)
x = f[j | k], y = 1ll * q * f[i | j | k] % yyb, f[j | k] = (x + y) % yyb, f[i | j | k] = (x - y) % yyb;
}
}
int fac[N], invFac[N], f[N], g[N], h[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
int n = rd(), m = n << 1 | 1, k = rd(), l = rd(), i, len, tmp, ans = 0;
fac[0] = 1;
for (i = 1; i <= m; ++i)
fac[i] = 1ll * fac[i - 1] * i % yyb;
invFac[m] = power(fac[m], yyb - 2);
for (i = m; i; --i)
invFac[i - 1] = 1ll * invFac[i] * i % yyb;
for (i = k; i <= n; ++i)
f[i] = invFac[i];
for (i = 0; i <= n; ++i)
g[i] = i & 1 ? yyb - invFac[i] : invFac[i];
for (len = 1; len <= m; len <<= 1) {}
for (i = 1; i < len; ++i)
rev[i] = (rev[i >> 1] >> 1) | (i & 1 ? len >> 1 : 0);
for (i = 1; i < len; i <<= 1)
G[0][i] = power(Gg, (yyb - 1) / (i << 1)), G[1][i] = power(Gi, (yyb - 1) / (i << 1));
ntt(f, len, 0), ntt(g, len, 0);
for (i = 0; i < len; ++i)
f[i] = 1ll * f[i] * g[i] % yyb;
ntt(f, len, 1), tmp = power(len, yyb - 2);
for (i = 1; i <= n; ++i)
f[i] = 1ll * f[i] * tmp % yyb;
for (i = 1, tmp = 2; i <= n; tmp = (tmp << 1) % yyb, ++i)
h[i] = 1ll * fac[i] * fac[i] % yyb * tmp % yyb * invFac[i << 1 | 1] % yyb * invFac[n - i] % yyb;
for (i = k; i <= n; ++i)
ans = (1ll * f[i] * h[i] % yyb + ans) % yyb;
ans = 1ll * ans * fac[n] % yyb * l % yyb, printf("%d\n", (ans + yyb) % yyb);
return 0;
}
CF1153F Serval and Bonus Problem FFT的更多相关文章
- CF1153F Serval and Bonus Problem
Serval and Bonus Problem 1.转化为l=1,最后乘上l 2.对于一个方案,就是随便选择一个点,选在合法区间内的概率 3.对于本质相同的所有方案考虑在一起,贡献就是合法区间个数/ ...
- CF1153F Serval and Bonus Problem 【期望】
题目链接:洛谷 作为一只沉迷数学多年的蒟蒻OIer,在推柿子和dp之间肯定要选推柿子的! 首先假设线段长度为1,最后答案乘上$l$即可. 对于$x$这个位置,被区间覆盖的概率是$2x(1-x)$(线段 ...
- Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)
yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE ...
- Codeforces1153F Serval and Bonus Problem 【组合数】
题目分析: 我们思考正好被k个区间覆盖的情况,那么当前这个子段是不是把所有的点分成了两个部分,那么在两个部分之间相互连k条线,再对于剩下的分别连线就很好了?这个东西不难用组合数写出来. 然后我们要证明 ...
- CF1153 F. Serval and Bonus Problem(dp)
题意 一个长为 \(l\) 的线段,每次等概率选择线段上两个点,共选出 \(n\) 条线段,求至少被 \(k\) 条线段覆盖的长度期望. 数据范围 \(1 \le k \le n \le 2000, ...
- Codeforces 1153F Serval and Bonus Problem [积分,期望]
Codeforces 思路 去他的DP,暴力积分多好-- 首先发现\(l\)没有用,所以不管它. 然后考虑期望的线性性,可以知道答案就是 \[ \int_0^1 \left[ \sum_{i=k}^n ...
- @codeforces - 1153F@ Serval and Bonus Problem
目录 @description@ @solution@ @accepted code@ @details@ @description@ 从一条长度为 l 的线段中随机选择 n 条线段,共 2*n 个线 ...
- 2016 acm香港网络赛 A题. A+B Problem (FFT)
原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/arch ...
- XJTUOJ wmq的A×B Problem FFT/NTT
wmq的A×B Problem 发布时间: 2017年4月9日 17:06 最后更新: 2017年4月9日 17:07 时间限制: 3000ms 内存限制: 512M 描述 这是一个非常简 ...
随机推荐
- 解决ArrayList线程不安全
前些天做项目时,程序出现意外的问题,经后来分析是使用ArrayList这个线程不安全的方法导致 解决这个问题通常有两种方法(个人认为) 一:使用synchronized关键字,这个大家应该都很熟悉了, ...
- drupal 2006 mysql server has gone away
在开发一个cms drupal网站时遇到了如上图的错误,几经百度谷歌,都一致说需要修改mysql的配置 max_allowed_packet参数,但是由于我买的是虚拟主机,并没有权限修改. 本来已经放 ...
- Scrapy爬虫入门
1.安装Scrapy 打开Anaconda Prompt,执行:pip install Scrapy执行安装! 注意:要是安装过程中抛出: error: Microsoft Visual C++ 14 ...
- [20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED3.txt
[20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED3.txt --//简单探究12c TABLE ACCESS BY INDEX ROWID BATCH ...
- [20170705]理解linux su命令.txt
[20170705]理解linux su命令.txt --//我一般在维护时经常使用root用户登录,然后su - oracle 转到其他用户操作--//一般都加入 - 参数.这个已经成了条件反射.. ...
- CTR预估中GBDT与LR融合方案
1. 背景 CTR预估(Click-Through Rate Prediction)是互联网计算广告中的关键环节,预估准确性直接影响公司广告收入.CTR预估中用的最多的模型是LR(Logistic R ...
- oracle 日期格式化 TO_CHAR (datetime) 修饰语和后缀
Datetime Format Element Suffixes Suffix Meaning Example Element Example Value TH Ordinal Number DDTH ...
- Windows端部署zabbix-agent
一.windows客户端的配置关闭windows防火墙或者开通10050和10051端口(1).关闭防火墙(不推荐直接关闭,测试可以这样做,尤其是最近勒索病毒猛烈)开始—控制面板—windows防火墙 ...
- [java基础]一文理解java多线程必备的sychronized关键字,从此不再混淆!
java并发编程中最长用到的关键字就是synchronized了,这里讲解一下这个关键字的用法和容易混淆的地方. synchronized关键字涉及到锁的概念, 在java中,synchronized ...
- Android Studio打开SDK更新对话框
再进行android自动化时,有时需要用到android的一些api,但苦于找不到 api文档,各种论坛查看是否有自己所需要的api,甚是麻烦.下面介绍如何通过 android studio将 and ...