令 g i g_i gi表示至少 i i i对情侣坐一起的方案数
显然 g j = ( n j ) 2 j ! 2 j ( 2 n − 2 j ) ! g_j={n\choose j}^2j!2^j(2n-2j)! gj=(jn)2j!2j(2n−2j)!
令
a
n
s
i
ans_i
ansi表示恰好
i
i
i对情侣坐一起的方案
显然有
g
i
=
∑
j
=
i
n
(
j
i
)
a
n
s
j
g_i=\sum_{j=i}^n {j\choose i}ans_j
gi=∑j=in(ij)ansj
二项式反演得
a
n
s
i
=
∑
j
=
i
n
(
−
1
)
j
−
i
(
j
i
)
g
j
=
∑
j
=
i
n
(
−
1
)
j
−
i
(
j
i
)
(
n
j
)
2
j
!
2
j
(
2
n
−
2
j
)
!
=
∑
j
=
i
n
(
−
1
)
j
−
i
j
!
i
!
(
j
−
i
)
!
n
!
2
j
!
2
(
n
−
j
)
!
2
j
!
2
j
(
2
n
−
2
j
)
!
=
∑
j
=
0
n
−
i
(
−
1
)
j
1
i
!
j
!
2
i
+
j
n
!
2
(
n
−
j
−
i
)
!
2
(
2
n
−
2
j
−
2
i
)
!
=
n
!
2
2
i
i
!
∑
j
=
0
n
−
i
(
−
1
)
j
1
j
!
2
j
1
(
n
−
j
−
i
)
!
2
(
2
n
−
2
j
−
2
i
)
!
ans_i=\sum_{j=i}^n(-1)^{j-i}{j\choose i}g_j\\ =\sum_{j=i}^n(-1)^{j-i}{j\choose i}{n\choose j}^2j!2^j(2n-2j)!\\ =\sum_{j=i}^{n}(-1)^{j-i}\frac{j!}{i!(j-i)!}\frac{n!^2}{j!^2(n-j)!^2}j!2^j(2n-2j)!\\ =\sum_{j=0}^{n-i}(-1)^j\frac{1}{i!j!}2^{i+j}\frac{n!^2}{(n-j-i)!^2}(2n-2j-2i)!\\ =\frac{n!^22^i}{i!}\sum_{j=0}^{n-i}(-1)^j\frac 1 {j!}2^j\frac{1}{(n-j-i)!^2}(2n-2j-2i)!
ansi=j=i∑n(−1)j−i(ij)gj=j=i∑n(−1)j−i(ij)(jn)2j!2j(2n−2j)!=j=i∑n(−1)j−ii!(j−i)!j!j!2(n−j)!2n!2j!2j(2n−2j)!=j=0∑n−i(−1)ji!j!12i+j(n−j−i)!2n!2(2n−2j−2i)!=i!n!22ij=0∑n−i(−1)jj!12j(n−j−i)!21(2n−2j−2i)!
里面只和 n − i n-i n−i有关系
定义 f ( n ) = ∑ j = 0 n ( − 1 ) j 1 j ! 2 j 1 ( n − j ) ! 2 ( 2 n − 2 j ) ! f(n)=\sum_{j=0}^n(-1)^j\frac{1}{j!}2^j\frac{1}{(n-j)!^2}(2n-2j)! f(n)=∑j=0n(−1)jj!12j(n−j)!21(2n−2j)!
则 a n s i = n ! 2 2 i i ! f ( n − i ) ans_i=\frac{n!^22^i}{i!}f(n-i) ansi=i!n!22if(n−i)
O ( n 2 ) O(n^2) O(n2)预处理 f f f可以 O ( n ) O(n) O(n)回答每个询问
#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
#define poly vector<int>
#define bg begin
cs 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 void chemx(int &a,int b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
cs int N=2005;
int fac[N],ifac[N],bin[N];
int n,f[N];
#define P(x) mul((x),(x))
inline int calc(int n){
int res=0;
for(int j=0;j<=n;j++)
if(j&1)Dec(res,mul(bin[j],mul(ifac[j],mul(P(ifac[n-j]),fac[2*n-2*j]))));
else Add(res,mul(bin[j],mul(ifac[j],mul(P(ifac[n-j]),fac[2*n-2*j]))));
return res;
}
inline int C(int n,int m){
if(n<m)return 0;
return mul(fac[n],mul(ifac[m],ifac[n-m]));
}
inline void init(int len=N-5){
bin[0]=fac[0]=ifac[0]=1;
for(int i=1;i<=len;i++)fac[i]=mul(fac[i-1],i);
ifac[len]=ksm(fac[len],mod-2);
for(int i=len-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
for(int i=1;i<=len;i++)bin[i]=mul(bin[i-1],2);
for(int i=0;i<=1000;i++)f[i]=calc(i);
}
int main(){
init();
int T=read();
while(T--){
int n=read();
for(int i=0;i<=n;i++)
cout<<mul(f[n-i],mul(ifac[i],mul(P(fac[n]),bin[i])))<<'\n';
}
}