[CTS2019] 珍珠

\(\text{Problem}:\)[CTS2019] 珍珠

\(\text{Solution}:\)

\(c_{i}\) 表示数 \(i\) 被取到的次数,\(d\) 表示 \(c_{i}\) 为奇数的 \(i\) 的个数。对于一种方案,其合法的充要条件为 \(\sum\limits_{i=1}^{D}\lfloor\frac{c_{i}}{2}\rfloor\geq m\),即 \(d\leq n-2m\)。首先特判 \(n-2m\geq D\)\(n-2m\) 的情况。

\(f_{i}\) 表示恰好 \(d=i\) 的方案数,\(g_{i}\) 表示钦定 \(d=i\) 的方案数。易知一种颜色选择奇数个的 \(\text{EGF}\)\(\frac{e^{x}-e^{-x}}{2}\),故有:

\[\begin{aligned} g_{i}&=\binom{D}{i}\left(\frac{e^{x}-e^{-x}}{2}\right)^{i}(e^{x})^{D-i}[\frac{x^{n}}{n!}]\\ &=\frac{1}{2^{i}}\binom{D}{i}\left(e^{x}-e^{-x}\right)^{i}(e^{x})^{D-i}[\frac{x^{n}}{n!}] \end{aligned} \]

利用二项式定理将 \((e^{x}-e^{-x})^{i}\) 展开,有:

\[\begin{aligned} g_{i}&=\frac{1}{2^{i}}\binom{D}{i}(e^{x})^{D-i}[\frac{x^{n}}{n!}]\sum\limits_{j=0}^{i}\binom{i}{j}e^{x(i-j)}(-1)^{j}e^{-xj}\\ &=\frac{1}{2^{i}}\binom{D}{i}e^{xD}[\frac{x^{n}}{n!}]\sum\limits_{j=0}^{i}\binom{i}{j}e^{-2xj}(-1)^{j}\\ &=\frac{1}{2^{i}}\binom{D}{i}\sum\limits_{j=0}^{i}\binom{i}{j}[\frac{x^{n}}{n!}]e^{(D-2j)x}(-1)^{j}\\ &=\frac{1}{2^{i}}\binom{D}{i}\sum\limits_{j=0}^{i}\binom{i}{j}(D-2j)^{n}(-1)^{j}\\ &=\frac{D^{\underline{i}}}{2^{i}}\sum\limits_{j=0}^{i}\frac{(-1)^{j}(D-2j)^{n}}{j!}\cdot\frac{1}{(i-j)!} \end{aligned} \]

\(\sum\) 内是一个卷积形式,利用 \(\text{NTT}\) 可以在 \(O(n\log n)\) 的时间复杂度内求出 \(g_{i}\)。由二项式反演得到:

\[\begin{aligned} f_{i}&=\sum\limits_{j=i}^{D}(-1)^{j-i}\binom{j}{i}g_{j}\\ &=\frac{1}{i!}\sum\limits_{j=0}^{D-i}\frac{(-1)^{j}}{j!}(i+j)!g_{i+j} \end{aligned} \]

将序列 \((i+j)!g_{i+j}\) 反转后也是卷积形式,即可求出 \(f_{i}\)。总时间复杂度 \(O(n\log n)\)

\(\text{Code}:\)

#include <bits/stdc++.h>
#pragma GCC optimize(3)
//#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
#define vi vector<int>
#define vpi vector<pair<int,int>>
using namespace std; const int N=265010, Mod=998244353;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int D,n,m,K;
int rev[N],r[24][2],fac[N],inv[N];
inline int ksc(int x,int p) { int res=1; for(;p;p>>=1, x=1ll*x*x%Mod) if(p&1) res=1ll*res*x%Mod; return res; }
inline void Get_Rev(int T) { for(ri int i=0;i<T;i++) rev[i]=(rev[i>>1]>>1)|((i&1)?(T>>1):0); }
inline void DFT(int T,vector<int> &s,int type)
{
	for(ri int i=0;i<T;i++) if(rev[i]<i) swap(s[i],s[rev[i]]);
	for(ri int i=2,cnt=1;i<=T;i<<=1,cnt++)
	{
		int wn=r[cnt][type];
		for(ri int j=0,mid=(i>>1);j<T;j+=i)
		{
			for(ri int k=0,w=1;k<mid;k++,w=1ll*w*wn%Mod)
			{
				int x=s[j+k], y=1ll*w*s[j+mid+k]%Mod;
				s[j+k]=x+y;
				if(s[j+k]>=Mod) s[j+k]-=Mod;
				s[j+mid+k]=x-y;
				if(s[j+mid+k]<0) s[j+mid+k]+=Mod;
			}
		}
	}
	if(!type) for(ri int i=0,inv=ksc(T,Mod-2);i<T;i++) s[i]=1ll*s[i]*inv%Mod;
}
inline void NTT(int n,int m,vector<int> &A,vector<int> B)
{
	int len=n+m;
	int T=1;
	while(T<=len) T<<=1;
	Get_Rev(T);
	A.resize(T), B.resize(T);
	DFT(T,A,1), DFT(T,B,1);
	for(ri int i=0;i<T;i++) A[i]=1ll*A[i]*B[i]%Mod;
	DFT(T,A,0);
}
signed main()
{
	r[23][1]=ksc(3,119), r[23][0]=ksc(ksc(3,Mod-2),119);
	for(ri int i=22;~i;i--) r[i][0]=1ll*r[i+1][0]*r[i+1][0]%Mod, r[i][1]=1ll*r[i+1][1]*r[i+1][1]%Mod;
	D=read(), n=read(), m=read();
	K=n-m*2;
	if(K>=D) return printf("%d\n",ksc(D,n))&0;
	if(K<0) return puts("0")&0;
	fac[0]=1;
	for(ri int i=1;i<=D;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[D]=ksc(fac[D],Mod-2);
	for(ri int i=D;i;i--) inv[i-1]=1ll*inv[i]*i%Mod;
	K=D+1;
	vector<int> A,B;
	A.resize(K), B.resize(K);
	for(ri int i=0;i<K;i++)
	{
		A[i]=1ll*ksc((D-i*2+Mod)%Mod,n)*inv[i]%Mod;
		if(i&1) A[i]=Mod-A[i];
		B[i]=inv[i];
	}
	NTT(K,K,A,B);
	A.erase(A.begin()+K,A.end());
	for(ri int i=0,inv2=(Mod+1)/2,now=1;i<K;i++) A[i]=1ll*A[i]*now%Mod*fac[D]%Mod*inv[D-i]%Mod*fac[i]%Mod, now=1ll*now*inv2%Mod;
	reverse(A.begin(),A.end());
	for(ri int i=0;i<K;i++) if(i&1) B[i]=Mod-B[i];
	NTT(K,K,A,B);
	int ans=0;
	for(ri int i=0;i<=n-m*2;i++) ans=(ans+1ll*A[D-i]*inv[i]%Mod)%Mod;
	printf("%d\n",ans);
	return 0;
}
posted @ 2021-05-04 19:39  zkdxl  阅读(43)  评论(1编辑  收藏  举报