【BZOJ5093】【Lydsy1711月赛】—图的价值(第二类斯特林数+组合数学)

传送门


Hacker rankHacker\ rank原题付费获得可还行

考虑每一个点的贡献
枚举度数,其他所有点之间随便练

ans=2(n1)(n2)2i=0n1(n1i)ikans=2^{\frac{(n-1)*(n-2)}{2}}*\sum_{i=0}^{n-1}{n-1\choose i}i^k
由于nn个点都相同,所以最后乘一个nn

为了好写令n=n1n=n-1
ans=(n+1)2n(n1)2i=0n(ni)ikans=(n+1)*2^{\frac{n*(n-1)}{2}}*\sum_{i=0}^{n}{n\choose i}i^k
我们只考虑计算Ans=i=0n(ni)ikAns=\sum_{i=0}^n{n\choose i}i^k

由于ik=j=0i(i,k)S2(k,j)(ij)j!i^k=\sum_{j=0}^{i(这里取i,k都是一样的)}S_2(k,j){i\choose j}j!

Ans=i=0n(ni)j=0iS2(k,j)(ij)j!Ans=\sum_{i=0}^{n}{n\choose i}\sum_{j=0}^iS_2(k,j){i\choose j}j!

=j=0kS2(k,j)i=jn(ni)(ij)j!=\sum_{j=0}^k S_2(k,j)\sum_{i=j}^{n}{n\choose i}{i\choose j}j!

由于(ni)(ij)j!=n!i!(ni)!i!j!(ij)!j!=n!(ni!)(ij)!=nj(nj)!(ni)!(ij)!=nj(njij){n\choose i}{i\choose j}j! =\frac{n!}{i!(n-i)!}\frac{i!}{j!(i-j)!}j!=\frac{n!}{(n-i!)(i-j)!}\\ = \frac{n^{\underline j}*(n-j)!}{(n-i)!(i-j)!}=n^{\underline j}{n-j\choose i-j}

Ans=j=0kS2(k,j)nji=jn(njij)Ans=\sum_{j=0}^k S_2(k,j)n^{\underline j}\sum_{i=j}^{n}{n-j\choose i-j}

=j=0kS2(k,j)nji=0nj(nji)=\sum_{j=0}^k S_2(k,j)n^{\underline j}\sum_{i=0}^{n-j}{n-j\choose i}

=j=0kS2(k,j)nj2nj=\sum_{j=0}^k S_2(k,j)n^{\underline j}2^{n-j}

利用NTTNTT求出S2(k)S_2(k)就完了

#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read(){
    char ch=gc();
    int res=0,f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
#define re register
#define pb push_back
#define cs const
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
const int mod=998244353,G=3;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){
    for(;b;b>>=1,a=mul(a,a))(b&1)&&(res=mul(res,a));return res;
}
inline int Inv(int x){
    return ksm(x,mod-2);
}
const int N=200005;
int fac[N],ifac[N];
inline void init(){
    fac[0]=ifac[0]=1;
    for(int i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
    ifac[N-1]=Inv(fac[N-1]);
    for(int i=N-2;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(int n,int m){
    if(n<m)return 0;
    return mul(fac[n],mul(ifac[m],ifac[n-m]));
}
#define poly vector<int>
int rev[N<<2];
inline void init_rev(int lim){
    for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
}
inline void ntt(poly &f,int lim,int kd){
    for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
    int bas=kd==-1?G:((mod+1)/G);
    for(int mid=1,a0,a1;mid<lim;mid<<=1){
        int wn=ksm(bas,(mod-1)/(mid<<1));
        for(int i=0;i<lim;i+=(mid<<1)){
            int w=1;
            for(int j=0;j<mid;j++,Mul(w,wn)){
                a0=f[i+j],a1=mul(f[i+j+mid],w);
                f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
            }
        }
    }
    if(kd==-1)for(int i=0,inv=Inv(lim);i<lim;i++)Mul(f[i],inv);
}
inline poly operator *(poly &a,poly &b){
    int deg=a.size()+b.size()-1,lim=1;
    while(lim<deg)lim<<=1;
    init_rev(lim);
    a.resize(lim),b.resize(lim);
    ntt(a,lim,1),ntt(b,lim,1);
    for(int i=0;i<lim;i++)Mul(a[i],b[i]);
    ntt(a,lim,-1),a.resize(deg);
    return a;
}
int n,k;
poly f,g;
int main(){
    #ifdef Stargazer
    freopen("lx.cpp","r",stdin);
    #endif 
    n=read()-1,k=read();
    init();
    for(int i=0;i<=k;i++)f.pb((i&1)?mod-ifac[i]:ifac[i]);
    for(int i=0;i<=k;i++)g.pb(mul(ksm(i,k),ifac[i]));
    poly s=f*g;
    int res=0;
    for(int i=0,t=1,nn=n+1,inv=Inv(2),p=ksm(2,n);i<=k;i++,Mul(t,--nn),Mul(p,inv))
        Add(res,mul(s[i],mul(t,p)));
    Mul(res,n+1);
    Mul(res,ksm(2,1ll*n*(n-1)/2%(mod-1)));
    cout<<res;
}
posted @ 2019-07-31 16:39  Stargazer_cykoi  阅读(144)  评论(0编辑  收藏  举报