ICM Technex 2018 and Codeforces Round #463 E. Team Work__codeforces

Source: Internet
Author: User
Tags pow

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.