题解 P4921 【情侣?给我烧了!】

fwat699

2018-10-17 21:23:35

题解

题意

题意很清楚 \滑稽

分析

代码

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define pb push_back
typedef long long LL;
inline int gi(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
    return x*f;
}
template<typename T>inline bool Max(T &a,T b){return a<b?a=b,1:0;}
template<typename T>inline bool Min(T &a,T b){return b<a?a=b,1:0;}
const int N=2004,mod=998244353;
int T,n;
LL fac[N],inv[N],invfac[N],bin[N],g[N];
void add(LL &a,LL b){a+=b;if(a>=mod) a-=mod;}
LL Pow(LL a,LL b){
    LL res=1ll;
    for(;b;b>>+1,a=a*a%mod) if(b&1) res=res*a%mod;
    return res;
}
LL C(int n,int m){
    return fac[n]*invfac[n-m]%mod*invfac[m]%mod;
}
int main(){
    fac[0]=invfac[0]=inv[1]=bin[0]=1;
    rep(i,1,N-1){
        if(i^1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fac[i]=fac[i-1]*i%mod;
        invfac[i]=invfac[i-1]*inv[i]%mod;
        bin[i]=bin[i-1]*2%mod;
    }

    g[0]=1,g[1]=0;
    rep(n,2,1000) g[n]=4ll*n*(n-1)%mod*(g[n-1]+2*(n-1)*g[n-2])%mod;

    T=gi();
    while(T--){
        n=gi();
        rep(k,0,n) printf("%lld\n",C(n,k)*C(n,k)%mod*fac[k]%mod*bin[k]%mod*g[n-k]%mod);
    }
    return 0;
}

blog