Dice (I)

 

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

Now you are given N, K, S; you have to 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: 57286574

Case 4: 72413502

Case 5: 9

Source

 
题意:给你n个骰子,每个骰子有1-k个分数,问你多少种方式的和是S
题解:  首先dp[i][j]表示前i个骰子,和为S的方案数
    那么 dp[i][j]=dp[i-1][j-1]+............+dp[i-1][j-k];
    对于i完全由i-1的状态得到,我们这可以用   sum[j]表示 dp[i-1][1到j]的一个前缀和,
    用i表示当前要计算的now状态,last表示i-1的状态 由此我们可以 得到dp[now][j]=sum[j-1]-sum[j-k-1];
    最终答案就是dp[now][s];

///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define memfy(a) memset(a,-1,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mod 100000007
#define inf 100000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************** #define maxn 15000+5
ll dp[][maxn],sum[maxn];
int n,k,s;
int main()
{ int T=read();
int oo=;
while(T--)
{
scanf("%d%d%d",&n,&k,&s);
int last=,now=;
mem(dp);
dp[now][]=;
for(int i=;i<=n;i++)
{
swap(last,now);
mem(dp[now]);
sum[]=dp[last][];
for(int j=;j<=s;j++)
{
sum[j]=(sum[j-]+dp[last][j])%mod;
}
for(int j=;j<=s;j++)
{
if(j<=k) dp[now][j]=(sum[j-])%mod;
else
dp[now][j]=(sum[j-]-sum[j-k-]+mod)%mod;
}
}
printf("Case %d: ",oo++);
cout<<dp[now][s]<<endl;;
}
return ;
}

代码

最新文章

  1. 升级到Windows10
  2. CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡
  3. PAAS平台的web应用性能测试与分析
  4. 洛谷P2724 联系 Contact
  5. 性能优化工具 MVC Mini Profiler
  6. 【转】Android Service被关闭后自动重启,解决被异常kill 服务
  7. keystone之预备知识点
  8. bzoj3878
  9. Activity组件的UI实现
  10. 使用IRP进行文件操作
  11. Delphi 客户端调用Webservice 的TClientdataset 报出“http://www.borland.com/namespaces/Types-IAppServerSOAP”
  12. Java代码优化(转)
  13. CABasicAnimation 基础
  14. 面试(4)-spring-Spring面试题和答案
  15. python的小基础
  16. nrf52832-定时器例程
  17. android -------- ConstraintLayout Group和goneMargin(五)
  18. 本地开发spark代码上传spark集群服务并运行
  19. ROS学习材料/链接
  20. javascript mediator pattern

热门文章

  1. Linux的网卡由eth0变成了eth1或eth2,如何修复??
  2. 并发编程学习笔记(11)----FutureTask的使用及实现
  3. JavaScipt30(第二个案例)
  4. for循环,字典遍历(二)
  5. ORACLE 查看当前用户信息(用户,表视图,索引,表空间,同义词,存储过程,约束条件)
  6. 网络基础——UDP
  7. 【tips】xadmin - django第三方后台管理系统
  8. BZOJ 4919 [Lydsy1706月赛]大根堆 (SRM08 T3)
  9. A - Restaurant
  10. Maven学习总结(29)——Maven项目的pom.xml中log4j2配置