第一类斯特林数·行

\(\text{Problem}:\)第一类斯特林数·行

\(\text{Solution}:\)

设第 \(n\) 行第一类斯特林数的 \(\text{OGF}\)\(F_{n}(x)\),有:

\[\begin{aligned} F_{n}(x)&=\sum\limits_{i=0}^{\infty}{n\brack i}x^{i}\\ &=(n-1)\sum\limits_{i=0}^{\infty}{n-1\brack i}x^{i}+\sum\limits_{i=0}^{\infty}{n-1\brack i-1}x^{i}\\ &=(n-1+x)F_{n-1}(x) \end{aligned} \]

易知 \(F_{0}(x)=1\),得到:

\[F_{n}(x)=\prod\limits_{i=1}^{n}(i-1+x)=x^{\overline{n}} \]

考虑 \(F_{2n}(x)=F_{n}(x)F_{n}(x+n)\),那么问题转化为已知 \(F_{n}(x)\),快速求出 \(F_{n}(x+n)\)。设 \(v_{i}\) 表示 \(F_{n}(x)\) 的第 \(i\) 项的系数,有:

\[\begin{aligned} F_{n}(x+n)&=\sum\limits_{i=0}^{n}v_{i}(x+n)^{i}\\ &=\sum\limits_{i=0}^{n}v_{i}\sum\limits_{j=0}^{i}x^{j}n^{i-j}\binom{i}{j}\\ &=\sum\limits_{j=0}^{n}x_{j}\sum\limits_{i=j}^{n}v_{i}n_{i-j}\binom{i}{j}\\ &=\sum\limits_{j=0}^{n}x_{j}\sum\limits_{i=j}^{n}\cfrac{v_{i}n^{i-j}i!}{j!(i-j)!}\\ &=\sum\limits_{j=0}^{n}\cfrac{x_{j}}{j!}\sum\limits_{i=j}^{n}v_{i}i!\cdot \cfrac{n^{i-j}}{(i-j)!}\\ &=\sum\limits_{j=0}^{n}\cfrac{x_{j}}{j!}\sum\limits_{i=0}^{n-j}v_{i+j}(i+j)!\cdot \cfrac{n^{i}}{i!} \end{aligned} \]

\(A_{i}=v_{n-i}\times(n-i)!,B_{i}=\dfrac{n^{i}}{i!}\),有:

\[\begin{aligned} F_{n}(x+n)&=\sum\limits_{j=0}^{n}\cfrac{x_{j}}{j!}\sum\limits_{i=0}^{n-j}A_{n-i-j}B_{i}\\ &=\sum\limits_{j=0}^{n}\cfrac{x_{j}}{j!}C_{n-j} \end{aligned} \]

利用 \(\text{NTT}\) 可以在 \(O(n\log n)\) 的时间复杂度内求出 \(F_{n}(x+n)\),再和 \(F_{n}(x)\) 做一次卷积就得到了 \(F_{2n}(x)\)。如此倍增求解,易知总时间复杂度为 \(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=550010, Mod=167772161;
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 n;
int rev[N],fac[N+5],inv[N+5],r[26][2];
vector<int> F;
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)%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);
	for(ri int i=n+1;i<T;i++) A[i]=0;
	for(ri int i=m+1;i<T;i++) B[i]=0;
	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);
}
void Solve(int n,vector<int> &F)
{
	if(!n) { F[0]=1; return; }
	if(n&1)
	{
		Solve(n-1,F);
		for(ri int i=n;i;i--) F[i]=(1ll*F[i]*(n-1)%Mod+F[i-1])%Mod;
		F[0]=1ll*F[0]*(n-1)%Mod;
		return;
	}
	int m=n/2;
	Solve(m,F);
	vector<int> A,B;
	A.resize(m+1), B.resize(m+1);
	for(ri int i=0,now=1;i<=m;i++)
	{
		A[i]=1ll*F[m-i]*fac[m-i]%Mod;
		B[i]=1ll*now*inv[i]%Mod;
		now=1ll*now*m%Mod;
	}
	NTT(m,m,A,B);
	vector<int> G;
	G.resize(m+1);
	for(ri int i=0;i<=m;i++) G[i]=1ll*A[m-i]*inv[i]%Mod;
	NTT(m,m,F,G);
}
signed main()
{
	r[25][1]=ksc(3,5), r[25][0]=ksc(ksc(3,Mod-2),5);
	for(ri int i=24;~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;
	fac[0]=1;
	for(ri int i=1;i<=N;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[N]=ksc(fac[N],Mod-2);
	for(ri int i=N;i;i--) inv[i-1]=1ll*inv[i]*i%Mod;
	n=read();
	F.resize(n+1);
	Solve(n,F);
	for(ri int i=0;i<=n;i++) printf("%d ",F[i]);
	puts("");
	return 0;
}
posted @ 2021-04-18 14:16  zkdxl  阅读(96)  评论(0编辑  收藏  举报