CF932E Team Work

Link

\[\begin{aligned} ans&=\sum\limits_{i=1}^n{n\choose i}i^k\\ &=\sum\limits_{i=1}^n\frac{n!}{i!(n-i)!}\sum\limits_{j=1}^{\min(i,k)}\left\{k\atop j\right\}i^{\underline j}\\ &=\sum\limits_{i=1}^n\sum\limits_{j=1}^{\min(i,k)}\left\{k\atop j\right\}\frac{n!}{(n-i)!(i-j)!}\\ &=\sum\limits_{i=1}^{\min(n,k)}\left\{k\atop i\right\}\sum\limits_{j=i}^n\frac{n!}{(n-j)!(j-i)!}\\ &=\sum\limits_{i=1}^{\min(n,k)}\left\{k\atop i\right\}\frac{n!}{(n-i)!}\sum\limits_{j=i}^n{n-i\choose n-j}\\ &=\sum\limits_{i=1}^{\min(n,k)}\left\{k\atop i\right\}\frac{n!}{(n-i)!}2^{n-i} \end{aligned} \]

#include<cstdio>
const int N=5001,P=1000000007;
int S[N][N];
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int pow(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int main()
{
    int n,k,ans=0;scanf("%d%d",&n,&k),S[0][0]=1;
    for(int i=1;i<=k;++i) for(int j=1;j<=i;++j) inc(S[i][j]=S[i-1][j-1],mul(j,S[i-1][j]));
    for(int i=1,t=n;i<=k&&i<=n;++i) inc(ans,1ll*S[k][i]*t%P*pow(2,n-i)%P),t=mul(t,n-i);
    printf("%d",ans);
}
posted @ 2020-04-14 21:04  Shiina_Mashiro  阅读(78)  评论(0编辑  收藏  举报