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道题的 ...
随机推荐
- 正整数序列 Help the needed for Dexter ,UVa 11384
题目描述 Description 给定正整数n,你的任务是用最少的操作次数把序列1, 2, …, n中的所有数都变成0.每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数.比如,1,2,3 ...
- Electron-vue中通过WebAudioApi实现录音功能,并转换为mp3格式,实时监测音频设备变化
实现以下功能: 1.检测当前音频环境,是否支持录音(WebAudio Api): 2.获取输入.输出设备列表,获取电脑默认的音频设备: 3.试音功能,通过分析录音样本数据,判断是否录到声音: 4.实时 ...
- 测试人员必须掌握的linu常用命令
有些公司需要测试人员部署程序包,通过工具xshell. 现在我将总结下工作需要用到的最多的命令 ls 显示文件或目录 pwd ...
- centos7上使用git clone出现问题
centos 7 git clone时出现不支持协议版本的问题 unable to access 'https://github.com/baloonwj/TeamTalk.git/': Peer ...
- php的文件上传及下载,附带显示文件及目录
主页面wenjianceshi.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- UI5-技术篇-SAPUI5创建自定义控件
转载:https://www.nabisoft.com/tutorials/sapui5/creating-custom-controls-in-sapui5 https://sapui5.h ...
- Intellij里检出svn报错找不到svn解决办法
Intellij里检出svn报错找不到,解决办法: 1. 安装svn客户端: 2. 去掉settings->version control->subversion里的use command ...
- 7层网络以及5种Linux IO模型以及相应IO基础
一.七层网络模型 OSI是Open System Interconnection的缩写,意为开放式系统互联.国际标准化组织(ISO)制定了OSI模型,该模型定义了不同计算机互联的标准,它是一个七层的. ...
- [LeetCode] 137. 只出现一次的数字,其余三次 II ☆☆☆
描述 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 示例 1: 输 ...
- IDEA提示不区分大小写设置
File–>Settings–>Editor–>General–>Code Completion–>Mach case的勾取消掉就可以了 取消勾后效果如下