Light OJ 1102 problem makes problem combination number

Source: Internet
Author: User
Tags cas

Source: Light OJ 1102 problem makes problem

Test instructions: An integer n is decomposed into the number of K to add how many scheme numbers can be duplicated

Idea: M apples put n boxes how many schemes allow boxes empty boxes Null correspondence 0 answer is C (n+m-1, n-1)

First of all, if the answer is not allowed is C (m-1, n-1) intervening spaces m Apple has a m-1 gap in this m-1 neutral selection n-1 a divided into n parts each part is not empty

Now allowed to empty then add an apple to each box is equivalent to n+m an Apple into n parts n+m-1 a neutral n-1 C (n+m-1, n-1)

Each part is at least 1 to 1 is actually empty I started adding it to facilitate the use of the intervening spaces method


#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
Const LL mod = 1000000007;
const int MAXN = 2000010;
return a^p mod n fast power
LL A[MAXN];
ll Pow_mod (ll A, ll P, ll N)
{
	ll ans = 1;
	while (p)
	{
		if (p&1)
		{
			ans *= A;
			Ans%= n;
		}
		A *= A;
		a%= n;
		P >>= 1;
	}
	return ans;
}

ll C (ll N, ll m)
{
	ll x = a[n], y = a[n-m]*a[m]%mod;
	return X*pow_mod (y, mod-2, MoD)%mod;
}
int main ()
{
	a[0] = 1;
	for (int i = 1; I <= 2000000; i++)
	{
		a[i] = a[i-1]*i;
		A[i]%= mod;
	}	
	int cas = 0; 
	int T;
	scanf ("%d", &t); 
	while (t--)
	{
		LL n, m;
		scanf ("%lld%lld", &n, &m);
		printf ("Case%d:%lld\n", ++cas, C (n+m-1, m-1));
	}
	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.