CF1153F Serval and Bonus Problem

Link
首先我们考虑长度为\(1\)的情况,最后把答案乘上\(l\)即可。
随机一条线段,\(x\in[0,1]\)不被覆盖的概率为\(p(x)=2x(1-x)\)
利用二项分布的理论,\(x\in[0,1]\)被覆盖至少\(k\)次的概率为\(f(x)=\sum\limits_{i=k}^n{n\choose i}p(x)^i(1-p(x))^{n-i}\)
那么此时的答案就是\(\int_0^1f(x)\mathrm dx\)

\[\begin{aligned} ans&=\int_0^1f(x)\mathrm dx\\ &=\int_0^1\sum\limits_{i=k}^n{n\choose i}p(x)^i(1-p(x))^{n-i}\mathrm dx\\ &=\sum\limits_{i=k}^n{n\choose i}\int_0^1p(x)^i(1-p(x))^{n-i}\mathrm dx\\ &=\sum\limits_{i=k}^n{n\choose i}\int_0^1p(x)^i\sum\limits_{j=0}^{n-i}{n-i\choose j}(-p(x))^j\mathrm dx\\ &=\sum\limits_{i=k}^n{n\choose i}\sum\limits_{j=0}^{n-i}{n-i\choose j}\int_0^1p(x)^i(-p(x))^j\mathrm dx\\ &=\sum\limits_{i=k}^n{n\choose i}\sum\limits_{j=0}^{n-i}{n-i\choose j}(-1)^j2^{i+j}\int_0^1x^{i+j}(1-x)^{i+j}\mathrm dx\\ &=\sum\limits_{i=k}^n{n\choose i}\sum\limits_{j=0}^{n-i}{n-i\choose j}(-1)^j2^{i+j}\frac{((i+j)!)^2}{(2i+2j+1)!}\\ &=n!\sum\limits_{l=k}^n2^l\frac{(l!)^2}{(2l+1)!(n-l)!}\sum\limits_{i+j=l}\frac1{i!}\frac{(-1)^j}{j!} \end{aligned} \]

#include<cstdio>
#include<algorithm>
const int N=4097,P=998244353;
int lim,rev[N],w[N],fac[N],ifac[N],f[N],g[N],h[N];
int read(){int x;scanf("%d",&x);return x;}
int inc(int a,int b){return a+=b-P,a+(a>>31&P);}
int dec(int a,int b){return a-=b,a+(a>>31&P);}
int mul(int a,int b){return 1ll*a*b%P;}
int pow(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
void init(int n)
{
    int p=(lim=1<<(32-__builtin_clz(n)))>>1,g=pow(3,(P-1)/lim);
    w[p]=1,fac[0]=1;
    for(int i=1;i<lim;++i) rev[i]=(rev[i>>1]>>1)|(i&1? p:0);
    for(int i=p+1;i<lim;++i) w[i]=mul(w[i-1],g);
    for(int i=p-1;i;--i) w[i]=w[i<<1];
    for(int i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
    ifac[n]=pow(fac[n],P-2);
    for(int i=n;i;--i) ifac[i-1]=mul(ifac[i],i);
}
void NTT(int*a,int f)
{
    if(!~f) std::reverse(a+1,a+lim);
    for(int i=1;i<lim;++i) if(i<rev[i]) std::swap(a[i],a[rev[i]]);
    for(int i=1;i<lim;i<<=1) for(int j=0,d=i<<1;j<lim;j+=d) for(int k=0,x;k<i;++k) x=mul(a[i+j+k],w[i+k]),a[i+j+k]=dec(a[j+k],x),a[j+k]=inc(a[j+k],x);
    if(!~f) for(int i=0,x=P-(P-1)/lim;i<lim;++i) a[i]=mul(a[i],x);
}
int main()
{
    int n=read(),k=read(),l=read(),ans=0;
    init(2*n+1);
    for(int i=k;i<=n;++i) f[i]=ifac[i];
    for(int i=0;i<=n;++i) g[i]=i&1? P-ifac[i]:ifac[i];
    NTT(f,1),NTT(g,1);
    for(int i=0;i<lim;++i) f[i]=mul(f[i],g[i]);
    NTT(f,-1);
    for(int i=1,pw=2;i<=n;pw=inc(pw,pw),++i) h[i]=mul(mul(mul(mul(fac[i],fac[i]),pw),ifac[i*2+1]),ifac[n-i]);
    for(int i=k;i<=n;++i) ans=inc(ans,mul(f[i],h[i]));
    printf("%d",mul(mul(ans,fac[n]),l));
}
posted @ 2020-03-09 10:29  Shiina_Mashiro  阅读(193)  评论(0编辑  收藏  举报