Luogu

LOJ

分析

$$
\begin{aligned}
f(n)&=\sum_{i=0}^n\sum_{j=0}^iS(i,j)\times 2^j\times j!\\
&=\sum_{i=0}^n\sum_{j=0}^nS(i,j)\times 2^j\times j!\\
&=\sum_{j=0}^n2^j\times j!\sum_{i=0}^nS(i,j)\\
&=\sum_{j=0}^n2^j\times j!\sum_{i=0}^n\sum_{k=0}^j(-1)^k\frac{(j-k)^i}{k!(j-k)!}\\
&=\sum_{j=0}^n2^j\times j!\sum_{k=0}^j\frac{(-1)^k}{k!}\sum_{i=0}^n\frac{(j-k)^i}{(j-k)!}\\
&=\sum_{j=0}^n2^j\times j!\sum_{k=0}^j\frac{(-1)^k}{k!}\times\frac{(j-k)^{n+1}-1}{(j-k-1)\times(j-k)!}
\end{aligned}
$$

后面显然是卷积的形式,直接 NTT 即可。

代码

// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
using namespace std;
typedef long long ll;

int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=400000+10;
const int mod=998244353;
int qpow(int a,int b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

int n,fac[N],ifac[N],F[N],G[N];

int r[N];
void NTT(int* A,int n,int op) {
    for (int i=0;i<n;++i) if (i<r[i]) swap(A[i],A[r[i]]);
    for (int i=1;i<n;i<<=1) {
        int rot=qpow(op==1?3:332748118,(mod-1)/(i<<1));
        for (int j=0;j<n;j+=i<<1)
            for (int k=0,w=1;k<i;++k,w=1ll*w*rot%mod) {
                int x=A[j+k],y=1ll*w*A[j+k+i]%mod;
                A[j+k]=(x+y)%mod,A[j+k+i]=(x-y+mod)%mod;
            }
    }
    if (op==-1) { int inv=qpow(n,mod-2);
        for (int i=0;i<n;++i) A[i]=1ll*A[i]*inv%mod;
    }
}

int main() {
    n=read();
    fac[0]=1;
    for (int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);
    for (int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod;
    for (int i=0;i<=n;++i) F[i]=(i&1)?mod-ifac[i]:ifac[i];
    G[0]=1,G[1]=n+1;
    for (int i=2;i<=n;++i) G[i]=1ll*(qpow(i,n+1)-1+mod)*qpow(i-1,mod-2)%mod*ifac[i]%mod;
    int lim=1,l=-1;
    for (;lim<=n+n;lim<<=1,++l);
    for (int i=0;i<lim;++i) r[i]=(r[i>>1]>>1)|((i&1)<<l);
    NTT(F,lim,1),NTT(G,lim,1);
    for (int i=0;i<lim;++i) F[i]=1ll*F[i]*G[i]%mod;
    NTT(F,lim,-1);
    int ans=0;
    for (int i=0;i<=n;++i) ans=(ans+1ll*qpow(2,i)*fac[i]%mod*F[i])%mod;
    printf("%d\n",ans);
    return 0;
}
最后修改:2020 年 06 月 19 日 08 : 56 AM