BNU 13064 Dice (I) prefix and optimized DP

Source: Internet
Author: User

Dice (I)

You have N dices; Each of the them have K faces numbered from 1 to K. Now there are arranged the N dices in a line. You can rotate/flip any dice if you want. How many ways can set the top faces such so the summation of all the top faces equals S?

Now is given N, K, S; Calculate the total number of ways.

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) and S (0≤s≤15000).

Output

For each case print, the case number and the result modulo 100000007.

Sample Input
Sample Input Output for Sample Input

5

1 6 3

2 9 8

500 6 1000

800 800 10000

2 100 10

Case 1:1

Case 2:7

Case 3:57,286,574

Case 4:72,413,502

Case 5:9

Sourcejane Alam Jan Test Instructions: Give you n a dice, each dice have 1-k a score, ask you how many ways and is s Solving: First Dp[i][j] represents the first I dice, and the number of programs for S so Dp[i][j]=dp[i-1][j-1]+............+dp[i-1][j-k]; For i is completely by the state of the i-1, we can use Sum[j] to represent a prefix of dp[i-1][1 to J] and, using I to represent the now state to be computed, last represents the state of i-1 so that we can get dp[now][j]=sum[j-1]-sum[    J-K-1]; The final answer is Dp[now][s];
///1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineMemfy (a) memset (A,-1,sizeof (a));#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineMoD 100000007#defineINF 100000000inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************#defineMAXN 15000+5ll dp[2][MAXN],SUM[MAXN];intn,k,s;intMain () {intt=read (); intoo=1;  while(t--) {scanf ("%d%d%d",&n,&k,&s); intlast=0, now=1;          MEM (DP); dp[now][0]=1;  for(intI=1; i<=n;i++) {swap (last,now);            MEM (Dp[now]); sum[0]=dp[last][0];  for(intj=1; j<=s;j++) {Sum[j]= (sum[j-1]+DP[LAST][J])%MoD; }             for(intj=1; j<=s;j++)            {                if(j<=k) dp[now][j]= (sum[j-1])%MoD; ElseDp[now][j]= (sum[j-1]-sum[j-k-1]+MOD)%MoD; }} printf ("Case %d:", oo++); cout<<dp[now][s]<<Endl;; }    return 0;}
Code

BNU 13064 Dice (I) prefix and optimized DP

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.