题面
https://www.luogu.org/problem/CF932E
题解
先交换求和号、把$S2(i,j)$中$j>i$的部分去掉、再对角线替换、最后配个对$i$来说的“常数”,就把式子变成一个组合数了。
#include<iostream> #include<cstdio> using namespace std; #define mod 1000000007 #define inv2 500000004 #define ri register int #define N 5050 int pow(int a,int b){int s=1;while(b){if(b&1)s=1ll*s*a%mod;a=1ll*a*a%mod;b>>=1;}return s;} int n,k,s2[N][N],ans; int main() { scanf("%d%d",&n,&k);s2[0][0]=1; for(ri i=1;i<=k;++i) for(ri j=1;j<=k;++j) s2[i][j]=(s2[i-1][j-1]+1ll*s2[i-1][j]*j)%mod; for(ri j=0,pw=pow(2,n),nw=1;j<=min(n,k);pw=1ll*pw*inv2%mod,nw=1ll*nw*(n-j)%mod,++j) ans=(ans+1ll*s2[k][j]*nw%mod*pw%mod)%mod; printf("%d ",ans); return 0; }