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 n, m, 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.
题解:如果前n列已经确定了,从第n列往后,每一列的数量也就确定了,所以我们求出前n列的就好,但是后面也会有根据这一列相继出现的次数 所以我们就可以得到表达式 dp[i][j] 表示前i列 有j个点的种类 我们可以得到表达式
dp[i][j]=∑k dp[i−1][k] ⋅ f[i][j−k] f[i][j]表示第i列放j个带来的所有种类数(包括后面的) 那么f[i][j] = C[n][j] ^ (与第i列等价的 (m-i+n)/n))
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=110;
const ll mod=1e9+7;
ll n,m,k;
ll dp[N][N*N],C[N][N],f[N][N];
ll ksm(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
int main()
{
C[0][0]=1,C[1][0]=1,C[1][1]=1;
for(int i=2;i<=100;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
while(~scanf("%lld%lld%lld",&n,&m,&k))
{
for(int i=1;i<=n;i++)
for(int j=0;j<=n;j++)
f[i][j]=ksm(C[n][j],(m-i+1+n-1)/n);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=min(k,n*i);j++)
{
int mm=min((int)n,j);
for(int kk=0;kk<=mm;kk++)
dp[i][j]=(dp[i][j]+dp[i-1][j-kk]*f[i][kk]%mod)%mod;
}
}
printf("%lld\n",dp[n][k]);
}
return 0;
}