Given N, K, seek ∑c (n,i) *i^k.
Ideas:
1. Derivative method: (1+x) ^n, continuous derivation. When the game thought of this approach, but no pen in hand without grass manuscript, brain pushing the pain, so ... Gave up.
2.DP:DP[I][J] Represents the number of items in the J box where I put something, and every box has something. The conversion of the equation to: ∑dp[k][i]*2^ (n-i)
Personal Appreciation Idea 2, from: http://blog.csdn.net/qq_36797743/article/details/79332455
AC Code:
#include <bits/stdc++.h>
#define R (N) scanf ("%d", &n)
#define RLL (n) scanf ("%lld", &n)
# Define MEM (A,b) memset (A,b,sizeof (a))
using namespace std;
typedef long long LL;
const LL MOD=1E9+7;
const int n=5001;
ll Dp[n][n];
ll Pow (ll X,ll y) {
if (y<0) return 0;
ll Ans=1;
while (y) {
if (y&1) ans= (ans*x)%mod;
x= (x*x)%mod;
y>>=1;
}
return ans;
}
int main () {
// C (n,i) *i^k => dp[i][j]*2^ (n-j) => dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1]* (n-j+1)
int n,k;
R (N); R (k);
Dp[0][0]=1;
for (int i=1;i<=k;i++) {for
(int j=1;j<=min (n,i); j + +) {
dp[i][j]=dp[i-1][j]*j%mod+dp[i-1][j-1]* (n-j +1)%mod;
Dp[i][j]%=mod
}
}
ll Ans=0;
for (int i=1;i<=min (n,k); i++) ans= (Ans+dp[k][i]*pow (2LL, (LL) n-i)%mod)%mod;
printf ("%i64d\n", ans);
return 0;
}