topic
https://codeforces.com/contest/932/problem/E
Chinese title: There are N (1≤N≤1e9) different people, from which you choose x (x is at least 1) individuals to complete a team task at a cost of xk (1≤k≤5000). Find the total cost of all team plans.
About the four arithmetic operations of derivatives: https://www.cnblogs.com/liming19680104/p/10955536.html
answer
It is easy to draw the question requirements① , where i=0 does not affect the answer.
It is easy to think of the binomial theorem when you see : ② ,
① is very similar to ②, and ② is much better than ①. How to change ② into ①?
The answer is: seek derivation
② If the derivative of formula is multiplied by x, then x is multiplied by the derivative, repeat, becomes , , ..., k times becomes later reuse , since x is a number we arbitrarily taken, to make it equal to 1. The right side of formula ② finally becomes , so just calculate the derivative result of the left side of formula ② to get the answer
②The transformation process on the left side of the formula:
once:
At this time the function becomes two functions , multiplication, according to the derivative of the four arithmetic operations
The following transformations can be made:
In this way , each term of the form ( for the coefficient of this term) can be changed to ,
Perform k times of transformation, and produce k items at most, and the elimination of items is not counted. Use dp to maintain the coefficient and complexity
Code
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define MAXN 5005
#define MOD 1000000007ll
using namespace std;
inline ll read(){
ll x=0,f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){if(s=='-')f*=-1;s=getchar();}
while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+s-'0';s=getchar();}
return x*f;
}
int k;
ll n,dp[MAXN],ans;
inline ll ksm(ll a,ll b,ll mo){
ll res=1;
for(;b;b>>=1){
if(b&1)res=res*a%mo;
a=a*a%mo;
}
return res;
}
int main()
{
n=read(),k=read();
dp[1]=n;
for(int i=2;i<=k;i++)
for(int j=i;j>0;j--)
dp[j]=(dp[j-1]*(n-j+1)+dp[j]*j)%MOD;
for(int i=1;i<=k;i++)
if(n-i>=0)ans=(ans+dp[i]*ksm(2,n-i,MOD))%MOD;//令x等于1
printf("%lld\n",ans);
return 0;
}