Time Limit: 3 second(s) | Memory Limit: 32 MB |
You have N dices; each of them has K faces numbered from 1 to K. Now you can arrange the N dices in a line. If the summation of the top faces of the dices is S, you calculate the score as the multiplication of all the top faces.
Now you are given N, K, S; you have to calculate the summation of all the scores.
Input
Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case contains three integers: N (1 ≤ N ≤ 1000) K (1 ≤ K ≤ 1000) S (0 ≤ S ≤ 15000).
Output
For each case print the case number and the result modulo 100000007.
Sample Input |
Output for Sample Input |
5 1 6 3 2 9 8 500 6 1000 800 800 10000 2 100 10 |
Case 1: 3 Case 2: 84 Case 3: 74335590 Case 4: 33274428 Case 5: 165 |
#include<stdio.h>
#include<string.h>
#define mod 100000007
long long dp[2][15008];
long long sum[15008];
int main()
{
int t,n,k,s,i,j,now,cas=1;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&k,&s);
memset(dp,0,sizeof(dp));
for(i=1;i<=k;i++) dp[1][i]=i;
for(i=2; i<=n; i++)
{
now=i&1;
memset(sum,0,sizeof(sum));
for(j=1; j<=s; j++)
{
sum[j]=(sum[j-1]+dp[now^1][j])%mod;
dp[now][j]=(dp[now][j-1]+sum[j-1])%mod;
if(j>k) dp[now][j]=((dp[now][j]-sum[j-k-1]-dp[now^1][j-k-1]*k)%mod+mod)%mod;
}
}
printf("Case %d: %lld\n",cas++,dp[n&1][s]);
}
return 0;
}