CF932E Team Workhtml
前置:斯特林數\(\Longrightarrow\)點這裏c++
\[\begin{aligned}\\ &\sum\limits_{i=1}^n C_n^ii^k\\ &\sum\limits_{i=1}^n C_n^i\sum\limits_{j=0}^iC_i^j\begin{Bmatrix}k\\j\end{Bmatrix}j!\\ &\sum\limits_{i=1}^n \frac{n!}{(n-i)!}\sum\limits_{j=0}^i\frac{\begin{Bmatrix}k\\j\end{Bmatrix}}{(i-j)!}\\ &\sum\limits_{j=0}^{min(n,k)}\begin{Bmatrix}k\\j\end{Bmatrix}\sum\limits_{i=j}^n\frac{n!}{(n-i)!}\frac{1}{(i-j)!}\\ &\sum\limits_{j=0}^{min(n,k)}\begin{Bmatrix}k\\j\end{Bmatrix}\sum\limits_{i=j}^n\frac{n!}{(n-j)!}\frac{(n-j)!}{(n-i)!(i-j)!}\\ &\sum\limits_{j=0}^{min(n,k)}\begin{Bmatrix}k\\j\end{Bmatrix}\frac{n!}{(n-j)!}\sum\limits_{i=j}^nC_{n-j}^{i-j}\\ &\sum\limits_{j=0}^{min(n,k)}\begin{Bmatrix}k\\j\end{Bmatrix}\frac{n!}{(n-j)!}2^{n-j}\\ \end{aligned}\]
至此咱們能夠經過\(O(k^2)\)處理第二類斯特林數達到\(O(n^2)\)經過此題spa
更多斯特林數及反演的姿式\(\Longrightarrow\)點這裏code
#include<bits/stdc++.h> typedef int LL; const LL maxn=5e3+9,mod=1e9+7,inv2=500000004; inline LL Pow(LL base,LL b){ LL ret(1); while(b){ if(b&1) ret=1ll*ret*base%mod; base=1ll*base*base%mod; b>>=1; }return ret; } LL ans[maxn][maxn]; inline void Fir(LL n){ ans[1][1]=1; for(LL i=2;i<=n;++i) for(LL j=1;j<=i;++j) ans[i][j]=1ll*(ans[i-1][j-1]+1ll*j*ans[i-1][j]%mod)%mod; } inline LL Get(LL l,LL r){ LL ret(1); for(LL i=l;i<=r;++i) ret=1ll*ret*i%mod; return ret; } LL n,k,ret; int main(){ scanf("%d%d",&n,&k); Fir(k); for(LL j=0,val1=1,val2=Pow(2,n);j<=k;++j,val1=1ll*val1*(n-j+1)%mod,val2=1ll*val2*inv2%mod) ret=1ll*(ret+1ll*ans[k][j]*val1%mod*val2%mod)%mod; printf("%d ",ret); }