1. 程式人生 > >【Table】【CodeForces - 232B】

【Table】【CodeForces - 232B】

題目:

John Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exactly k points.

John Doe wondered, how many distinct ways to fill the table with points are there, provided that the condition must hold. As this number can be rather large, John Doe asks to find its remainder after dividing by 1000000007 (109 + 7).

You should assume that John always paints a point exactly in the center of some cell. Two ways to fill a table are considered distinct, if there exists a table cell, that has a point in one way and doesn't have it in the other.

Input

A single line contains space-separated integers nm

k (1 ≤ n ≤ 100; n ≤ m ≤ 1018; 0 ≤ k ≤ n2) — the number of rows of the table, the number of columns of the table and the number of points each square must contain.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

In a single line print a single integer — the remainder from dividing the described number of ways by 1000000007 (109 + 7).

Examples

Input

5 6 1

Output

45

Note

Let's consider the first test case:

The gray area belongs to both 5 × 5 squares. So, if it has one point, then there shouldn't be points in any other place. If one of the white areas has a point, then the other one also must have a point. Thus, there are about 20 variants, where the point lies in the gray area and 25 variants, where each of the white areas contains a point. Overall there are 45 variants.

解題報告:剛上來確實是沒有理解題目的意思,後來看懂了,但是也只是理解了當k=1 的情況,所以很迷,之後又想了很久,這道題目卡了一個半小時,後來理解了,就是給定我們一個n*m的大矩陣,要求每個n*n的矩陣中都要有至少k個點,問放法的數量。發現了規律,第i列和第i+n行的放置個數是相同的,之後採用dp,dp[i][k]表示第i列放置了k個點了。會得到一個規律就是

在那列放置j個點的情況下,dp[i][k]+=dp[i-1][k-j]*C(n,j)^cnt;(j是需要列舉的,cnt是週期的數目)

ac程式碼:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll num[200][200];
ll dp[250][15000];
ll n,m,k;
ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
		{
			res=(res*a)%mod;
			b--;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=100;i++)
	{
		num[i][0]=1;
		num[i][i]=1;
		num[i][1]=i;
	}
	for(int i=2;i<=100;i++)
		for(int j=2;j<i;j++)
		{
			num[i][j]=(num[i-1][j]+num[i-1][j-1])%mod;
		}//組合數打表求值
	/*for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
			printf("%lld ",num[i][j]);
		printf("\n");
	}*/
	memset(dp,0,sizeof(dp));
	ll cnt=m/n;
	ll gb;
	if(m%n)
	{
		gb=m-cnt*n;
		cnt++;
	}
	else 
		gb=n;
	for(int i=0;i<=n;i++)
		dp[i][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=n&&j<=k;j++)
		{
			ll gg=num[n][j];
			ll gd;
			if((ll)i<=gb) gd=ksm(gg,cnt);
			else  gd=ksm(gg,cnt-1);
			for(int ll=j;ll<=k;ll++)
			{
				if(ll==0) continue;
				dp[i][ll] +=  dp[i-1][ll-j]*gd;
				dp[i][ll]%=mod;
			}
		}
/*	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
			printf("%lld ",dp[i][j]);
		printf("\n");
	}*/
	printf("%lld\n",(dp[n][k]+mod)%mod);
	return 0;
}