求$\sum_{i=1}^nC_{n}^i*i^k$
1 //minamoto 2 #include<iostream> 3 #include<cstdio> 4 using namespace std; 5 const int N=5005,P=1e9+7,inv2=500000004; 6 inline int ksm(int a,int b){ 7 int res=1; 8 while(b){ 9 if(b&1) res=1ll*res*a%P; 10 a=1ll*a*a%P,b>>=1; 11 } 12 return res; 13 } 14 int n,k,S[N][N],ans; 15 int main(){ 16 // freopen("testdata.in","r",stdin); 17 scanf("%d%d",&n,&k);S[0][0]=1; 18 for(int i=1;i<=k;++i) for(int j=1;j<=k;++j) 19 S[i][j]=(S[i-1][j-1]+1ll*j*S[i-1][j])%P; 20 for(int j=0,pw=ksm(2,n),nw=1;j<=min(n,k);pw=1ll*pw*inv2%P,nw=1ll*nw*(n-j)%P,++j) 21 ans=(ans+1ll*S[k][j]*nw%P*pw%P)%P; 22 printf("%d\n",ans); 23 return 0; 24 }
原文地址:https://www.cnblogs.com/bztMinamoto/p/9756064.html
时间: 2024-10-08 17:46:57