Codeforces 1153F Serval and Bonus Problem [积分,期望]
思路
去他的DP,暴力积分多好……
首先发现\(l\)没有用,所以不管它。
然后考虑期望的线性性,可以知道答案就是
\]
我们令
\]
暴力拆开,答案就是
\]
也就是
\]
后面只和\(i+j\)有关,可以预处理。
然后就可以\(O(n^2)\),然后就做完了……
我才不告诉你我没有换元然后硬生生地推出了\(O(n^4)\)的式子呢
我也不会告诉你我还硬生生地把它优化成了\(O(n^3)\)呢
我更不会告诉你我盯着它一下午没推出来呢
代码
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define sz 6000
#define mod 998244353ll
typedef long long ll;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t)
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
char __sr[1<<21],__z[20];int __C=-1,__zz=0;
inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
inline void print(register int x)
{
if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
while(__z[++__zz]=x%10+48,x/=10);
while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
}
void file()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifndef ONLINE_JUDGE
cout<<(clock()-t)/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
// inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;
ll fac[sz],_fac[sz];
void init(){_fac[0]=fac[0]=1;rep(i,1,sz-1) _fac[i]=inv(fac[i]=fac[i-1]*i%mod);}
ll C(int n,int m){return n>=m&&m>=0?fac[n]*_fac[m]%mod*_fac[n-m]%mod:0;}
int n,K;ll L;
ll f[sz],pow2[sz],Inv[sz];
ll ans;
int main()
{
file();
read(n,K,L);
init();
rep(i,1,sz-1) pow2[i]=ksm(2,i),Inv[i]=inv(i);
rep(N,1,n) rep(k,0,N) (f[N]+=Inv[N+k+1]*((k&1)?-1ll:1ll)*C(N,k)%mod+mod)%=mod;
rep(i,K,n) rep(j,0,n-i) (ans+=C(n,i)*((j&1)?-1ll:1ll)*C(n-i,j)%mod*pow2[i+j]%mod*f[i+j]%mod+mod)%=mod;
cout<<ans*L%mod;
return 0;
}
其他做法
这里讲一下标程的神仙DP。
考虑现在线段长度为1,那么可以发现在线段上随机丢一个点\(P\),那么\(P\)被\(k\)条线段覆盖的概率就是要求的答案。
于是我们可以发现只有点之间的相对位置对答案有影响,而在线段上的位置就不重要了。
然后概率再转计数,就是要求\(2n+1\)个点,设出\(n\)个左右端点和一个\(P\),使得满足那个性质的方案数。
然后DP:\(f_{i,j,x}\)表示前\(i\)个点,有\(j\)个左端点还没被匹配,\(P\)有没有被放下来,的方案数。
最后考虑互换左右端点、给线段编号,答案就是
\]
Codeforces 1153F Serval and Bonus Problem [积分,期望]的更多相关文章
- @codeforces - 1153F@ Serval and Bonus Problem
目录 @description@ @solution@ @accepted code@ @details@ @description@ 从一条长度为 l 的线段中随机选择 n 条线段,共 2*n 个线 ...
- CF1153F Serval and Bonus Problem 【期望】
题目链接:洛谷 作为一只沉迷数学多年的蒟蒻OIer,在推柿子和dp之间肯定要选推柿子的! 首先假设线段长度为1,最后答案乘上$l$即可. 对于$x$这个位置,被区间覆盖的概率是$2x(1-x)$(线段 ...
- CF1153F Serval and Bonus Problem FFT
CF1153F Serval and Bonus Problem 官方的解法是\(O(n ^ 2)\)的,这里给出一个\(O(n \log n)\)的做法. 首先对于长度为\(l\)的线段,显然它的答 ...
- CF1153F Serval and Bonus Problem
Serval and Bonus Problem 1.转化为l=1,最后乘上l 2.对于一个方案,就是随便选择一个点,选在合法区间内的概率 3.对于本质相同的所有方案考虑在一起,贡献就是合法区间个数/ ...
- 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 - 1264C - Beautiful Mirrors with queries - 概率期望dp
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\ ...
- 【codeforces 442B】 Andrey and Problem
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...
随机推荐
- C/C++ cmake example
学习 Golang,有时需要 Cgo,所以需要学习 C.C++. 语言入门: https://item.jd.com/12580612.html https://item.jd.com/2832653 ...
- interface Part4(接口中的多态)
使用接口实现多态 需要满足以下两个条件. 定义接口并使用类实现了接口中的成员. 创建接口的实例指向不同的实现类对象. 假设接口名称为 ITest,分别定义两个实现类来实现接口的成员,示例代码如下. i ...
- jQuery 事件介绍
什么是事件?页面对不同访问者的响应叫做事件.事件处理程序指的是当 HTML 中发生某些事件时所调用的方法. 常用的时间主要有以下几种: click()事件:click() 方法是当按钮点击事件被触发时 ...
- TensorFlow实现自编码器及多层感知机
1 自动编码机简介 传统机器学习任务在很大程度上依赖于好的特征工程,比如对数值型,日期时间型,种类型等特征的提取.特征工程往往是非常耗时耗力的,在图像,语音和视频中提取到有效的特征就更难 ...
- LNMP环境搭建BBS论坛及伪静态
我们在mysql备份 LNMP环境中的数据库迁移为独立的服务器的基础上搭建BBS论坛: [root@bqh-117 ~]# mysql -uroot -p123456 Welcome to the ...
- linux uniq命令用法
uniq命令: 对指定的ASCII文件或标准输入进行唯一性检查,以判断文本文件中重复出现的行,常用于分析日志:查看tcp各个状态连接数,ip或域名连接数排名等等场景,一般与 sort 命令结合使用. ...
- c# try 和 catch 块
- nginx全局配置和性能优化
nginx目录结构和命令 1.ls /apps/nginx/: html是测试页,sbin是主程序 2.ls /apps/nginx/sbin/: nginx 只有一个程序文件 3. ...
- CUDA中确定你显卡的thread和block数
CUDA中确定你显卡的thread和block数 在进行并行计算时, 你的显卡所支持创建的thread数与block数是有限制的, 因此, 需要自己提前确定够用, 再进行计算, 否则, 你需要改进你的 ...
- Codeforces Round #582 (Div. 3)-G. Path Queries-并查集
Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足 ...