CF932E Team Work 题解
see the right
set
so
just do it in
see the codes:
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inv2 = 500000004;
const int maxn = 5e3 + 5;
inline ll chk(ll x) { return x >= mod ? x-mod : x; }
inline ll fpm(ll a, ll k = mod-2) {
ll res = 1;
while(k) {
if(k&1) res = res*a % mod;
a = a*a % mod;
k >>= 1;
}
return res;
}
int n, k;
ll ans;
ll s[maxn][maxn];
inline void getstirling() {
s[0][0] = 1;
for(int i = 1; i <= k; i++)
for(int j = 1; j <= k; j++)
s[i][j] = chk(s[i-1][j-1] + 1ll * j * s[i-1][j] % mod);
}
int main() {
scanf("%d %d", &n, &k);
getstirling();
ll jc = 1, ef = fpm(2, n);
for(int i = 1; i <= k; i++) {
jc = jc * (n-i+1) % mod;
ef = ef * inv2 % mod;
ans = chk(ans + s[k][i] * jc % mod * ef % mod);
}
printf("%lld\n", ans);
return 0;
}