Solution S o l u t i o n
可能也算是裸题了咯。
求
∑i=1n(ni)ik
∑
i
=
1
n
(
n
i
)
i
k
用斯特林数把
ik
i
k
展开。
∑d=0kd!S(k,d)(nd)2n−d
∑
d
=
0
k
d
!
S
(
k
,
d
)
(
n
d
)
2
n
−
d
O(k2)
O
(
k
2
)
直接做了啦~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5050;
const int MOD = 1000000007;
int n, k;
int S[N][N];
int fac[N], ifac[N], inv[N];
inline int pwr(int a, int b) {
int c = 1;
while (b) {
if (b & 1) c = (ll)c * a % MOD;
b >>= 1; a = (ll)a * a % MOD;
}
return c;
}
inline void pre(int n) {
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
fac[0] = ifac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (ll)fac[i - 1] * i % MOD;
ifac[i] = (ll)ifac[i - 1] * inv[i] % MOD;
}
}
inline int C(int n, int m) {
int res = 1;
for (int i = 0; i < m; i++) {
res = (ll)res * (n - i) % MOD;
res = (ll)res * inv[i + 1] % MOD;
}
return res;
}
int main(void) {
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
cin >> n >> k;
pre(k);
S[0][0] = 1;
for (int i = 1; i <= k; i++) {
S[i][0] = 0;
for (int j = 1; j <= i; j++)
S[i][j] = ((ll)j * S[i - 1][j] + S[i - 1][j - 1]) % MOD;
}
int ans = 0;
for (int d = 0; d <= k && d <= n; d++) {
ans = (ans + (ll)fac[d] * S[k][d] % MOD * C(n, d) % MOD * pwr(2, n - d) % MOD) % MOD;
// cerr << d << endl;
}
cout << ans << endl;
return 0;
}