# cf932E. Team Work(第二类斯特灵数 组合数)

## Sol

$m^n = \sum_{i = 0}^m C_{n}^i S(n, i) i!$

$\sum_{i=1}^n\frac{n!}{(n-i)!}\sum_{j=0}^i\frac{S(k,j)}{(i-j)!}$

$\sum_{j = 0}^n S(k, j) \sum_{i = 1}^n \frac{n!}{(n - i)!} \frac{1}{(i - j)!}$

$\sum_{j=0}^{k}S(k,j)\frac{n!}{(n-j)!}2^{n-j}$

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5001, mod = 1e9 + 7, inv2 = 500000004;
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, K, s[MAXN][MAXN];
int fastpow(int a, int p) {
int base = 1;
while(p) {
if(p & 1) base = 1ll * base * a % mod;
a = 1ll * a * a % mod; p >>= 1;
}
return base;
}
int main() {
s[0][0] = 1;
cin >> N >> K;
for(int i = 1; i <= K; i++)
for(int j = 1; j <= K; j++)
s[i][j] = (s[i - 1][j - 1] + 1ll * s[i - 1][j] * j % mod) % mod;
int ans = 0, nv = 1, po2 = fastpow(2, N);
for(int i = 0; i <= min(K, N); po2 = 1ll * po2 * inv2 % mod, nv = 1ll * nv * (N - i) % mod, i++)
(ans += (1ll * s[K][i] * nv % mod * po2 % mod)) %= mod;
cout << ans % mod;
return 0;
}
posted @ 2018-09-29 11:23  自为风月马前卒  阅读(...)  评论(...编辑  收藏

……