【BZOJ5093】【Lydsy1711月赛】—图的价值(第二类斯特林数+组合数学)
原题付费获得可还行
考虑每一个点的贡献
枚举度数,其他所有点之间随便练
由于个点都相同,所以最后乘一个
为了好写令
我们只考虑计算
由于
由于
利用求出就完了
#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;
}