1145 - Dice (I)
Time Limit: 2 second(s) Memory Limit: 32 MB

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

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


Problem Setter: Jane Alam Jan
思路:dp;
这个很容易想到N3的思路;但是肯定GG;
那么我们需要优化。我们可以以前缀和的形式来dp;dp[i][j]表示选前i个空格,组成小与等于j大的数的种数,状态转移方程是dp[i][j]=dp[i][j-1]+dp[i-1][j-1]-dp[i-1][max(j-1-k,0)];
那么答案就是dp[x][z]-dp[x][z-1];由于内存的限制,所以我们可以用滚动数组。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<stack>
7 #include<map>
8 #include<math.h>
9 using namespace std;
10 typedef long long LL;
11 LL dp[2][16000];
12 int main(void)
13 {
14 int i,j,k;
15 scanf("%d",&k);
16 int s;
17 int x,y,z;
18 for(s=1; s<=k; s++)
19 {
20 memset(dp,0,sizeof(dp));
21 scanf("%d %d %d",&x,&y,&z);
22 printf("Case %d: ",s);
23 if(z==0)
24 printf("0\n");
25 else
26 {
27 for(i=1; i<=y; i++)
28 {
29 dp[1][i]=i;
30 }
31 for(i=y; i<=z; i++)
32 {
33 dp[1][i]=dp[1][y];
34 }
35 for(i=2; i<=x; i++)
36 {
37 dp[i%2][0]=0;
38 for(j=0; j<i; j++)
39 dp[i%2][j]=0;
40 for(j=i; j<=z; j++)
41 {
42 int cc=max(0,j-1-y);
43 dp[i%2][j]=dp[i%2][j-1]+dp[(i+1)%2][j-1]-dp[(i+1)%2][cc];
44 dp[i%2][j]%=100000007;
45 }
46 }
47 printf("%lld\n",((dp[x%2][z]-dp[x%2][z-1])% 100000007+ 100000007)% 100000007);
48 }
49 }
50 return 0;
51 }

GG

1145 - Dice (I)的更多相关文章

  1. lightoj 1145 - Dice (I)(dp+空间优化+前缀和)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1145 题解:首先只要是dp的值只和上一个状态有关系那么就可以优化一维,然后这题 ...

  2. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  3. 1193 - Dice (II)

    1193 - Dice (II)    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB You h ...

  4. HDOJ 4652 Dice

      期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 三种renderman规范引擎的dice对比

    次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...

  6. ural 1145. Rope in the Labyrinth

    1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular f ...

  7. LightOJ 1248 Dice (III) 概率

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  8. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. 概率 Gym 100502D Dice Game

    题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...

随机推荐

  1. C#gridview颜色提示

    OnRowCreated="gridStatistic_RowCreated private void FillUI() { gridStatistic.DataSource = dtSta ...

  2. IPv6 私有地址

    在互联网的地址架构中,专用网络是指遵守RFC 1918(IPV4)和RFC 4193(IPV6)规范,使用专用IP地址空间的网络.私有IP无法直接连接互联网,需要使用网络地址转换(Network Ad ...

  3. APK 反编译以及遇到的问题

    APK反编译: https://www.cnblogs.com/geeksongs/p/10864200.html 遇到的问题 https://www.jianshu.com/p/55bf5f688e ...

  4. vue2.x入门学习

    vue安装 # 最新稳定版本 $ npm install vue # 最新稳定 CSP 兼容版本 $ npm install vue@csp 引包 cd /d/vue/demo cnpm instal ...

  5. Oracle带输入输出参数的存储过程

    (一)使用输入参数 需求:在emp_copy中添加一条记录,empno为已有empno的最大值+1,ename不能为空且长度必须大于0,deptno为60. 创建存储过程: create or rep ...

  6. 【Linux】【Services】【Configuration】puppet

    1. 简介 1.1. 官方网站:https://docs.puppet.com/ 1.2. puppet是IT基础设施自动化管理工具,他的整个生命周期包括:provisioning,configura ...

  7. 网页设计单位 px,em,rem,vm,vh,%

    px(pixels) 像素 (px) 是一种绝对单位,因为无论其他相关的设置怎么变化,像素指定的值是不会变化的. px就是设备或者图片最小的一个点,比如常常听到的电脑像素是1024x768的,表示的是 ...

  8. jQuery中的html()、text()和val()的用法

    1.html() 获得的是第一个符合要求的标签中的所有内容,例如: var content = $("li").html(); <li>111<p>999& ...

  9. 一个超简单的Microsoft Edge Extension

    这个比微软官网上的例子简单很多,适合入门.总共4个文件: https://files.cnblogs.com/files/blogs/714801/cet6wordpicker.zip 36KB 1. ...

  10. redis实例cpu占用率过高问题优化

    目录 一.简介 一.简介 前情提要: 最近接了大数据项目的postgresql运维,刚接过来他们的报表系统就出现高峰期访问不了的问题,报表涉及实时数据和离线数据,离线读pg,实时读redis.然后自然 ...