Face questions
answer
我们知道有
\[ n^k = \sum_{i = 0}^{n}i!\binom{n}{i}\begin{Bmatrix}k\\i\end{Bmatrix} \]
所以有
\[ \displaystyle\begin{aligned}\sum_{i = 1}^{n}\binom{n}{i}i^k&=\sum_{i=0}^{n}\binom{n}{i}i^k-\begin{bmatrix}k=0\end{bmatrix}\\&= \sum_{i = 0}^{n}\binom{n}{i}\sum_{j=0}^{i}j!\binom{i}{j}\begin{Bmatrix}k\\j\end{Bmatrix}-\begin{bmatrix}k=0\end{bmatrix}\\&=\sum_{i = 0}^{n}\sum_{j=0}^{i}j!\begin{Bmatrix}k\\j\end{Bmatrix}\binom{n}{i}\binom{i}{j}-\begin{bmatrix}k=0\end{bmatrix}\end{aligned} \]
交换求和号
\[ \displaystyle=\sum_{j=0}^{min(n, k)}j!\begin{Bmatrix}k\\j\end{Bmatrix}\sum_{i=j}^{n}\binom{n}{i}\binom{i}{j} \]
因为 \(i < j\) 时, \(\binom{i}{j} = 0\)
\ [\ Displaystyle = \ sum_ { j = 0} ^ {min (n, k)} j! \ Begin {Bmatrix} k \\ j \ end {Bmatrix} \ sum_ {i = 0} ^ {n} \ binom {n} {i} \ binom
{i} {j} - \ begin {bmatrix} k = 0 \ end {bmatrix} \] see
\ [\ displaystyle \ sum_ {i = 0} ^ n \ binom {n} {i} \ binom {i}
{j} \] its meaning combinations, from \ (n-\) selected white balls in \ (I \) number of dyed black, and from \ (I \) black balls selected \ (j \) a dyed red
Because there is a \ (\ sum_ {i = 0 } ^ n \) so the final number of balls may be black \ (\ begin {bmatrix} 0 , nj \ end {bmatrix} \)
It is equivalent to the \ (n \) white balls selected \ (j \) a dyed red, the other will do just do not dye dye
It is
\ [\ displaystyle \ sum_ {i
= 0} ^ n \ binom {n} {i} \ binom {i} {j} = \ binom {n} {j} * 2 ^ {nj} \] substituting give
\ [\ displaystyle = \ sum_ { j = 0} ^ {min (n, k)} j! \ begin {bmatrix} k \\ j \ end {bmatrix} \ binom {n} {j} * 2 ^ {nj } - \ begin {bmatrix} k
= 0 \ end {bmatrix} \] pretreatment number and the number of combinations to Stirling
Code
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 5005;
const int mod = 1e9 + 7;
using namespace std;
int n, k, s[N][N], ans;
template < typename T >
inline T read()
{
T x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
}
int fpow(int x, int y)
{
int res = 1;
for( ; y; y >>= 1, x = 1ll * x * x % mod)
if(y & 1) res = 1ll * res * x % mod;
return res;
}
int main()
{
n = read <int> (), k = read <int> ();
s[0][0] = 1;
for(int i = 1; i <= k; i++)
for(int j = 0; j <= i; j++)
s[i][j] = (!j ? 0 : (s[i - 1][j - 1] + 1ll * j * s[i - 1][j] % mod) % mod);
for(int res, j = 0; j <= k; j++)
{
if(j > n) break;
res = 1;
for(int i = n; i > n - j; i--)
res = 1ll * res * i % mod;
ans = (ans + 1ll * s[k][j] * res % mod * fpow(2, n - j) % mod) % mod;
}
if(!k) ans--;
printf("%d\n", ans);
return 0;
}