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. Nginx编译参数详细介绍

    /configure --help --help 显示本提示信息 --prefix=PATH 设定安装目录 --sbin-path=PATH 设定程序文件目录 --conf-path=PATH 设定配 ...

  2. 云原生PaaS平台通过插件整合SkyWalking,实现APM即插即用

    一. 简介 SkyWalking 是一个开源可观察性平台,用于收集.分析.聚合和可视化来自服务和云原生基础设施的数据.支持分布式追踪.性能指标分析.应用和服务依赖分析等:它是一种现代 APM,专为云原 ...

  3. 修改linux系统下mysql数据库登陆密码(密码忘记)

    报错:Access denied for user 'root'@'localhost' (using password: NO) 解决方案: 1. 检查mysql服务是否启动,如果启动,关闭mysq ...

  4. Android系统编程入门系列之硬件交互——多媒体麦克风

    在多媒体摄像头及相关硬件文章中,对摄像头的使用方式需要区分应用程序的目标版本以使用不同的代码流程,而与之相比,麦克风硬件的使用就简单多了. 麦克风及相关硬件 麦克风硬件在移动设备上作为音频的采集设备, ...

  5. 商业爬虫学习笔记day7-------解析方法之bs4

    一.Beautiful Soup 1.简介 Beautiful Soup 是python的一个库,最主要的功能是从网页抓取数据.其特点如下(这三个特点正是bs强大的原因,来自官方手册) a. Beau ...

  6. 【Reverse】每日必逆0x00

    附件:https://files.buuoj.cn/files/aa4f6c7e8d5171d520b95420ee570e79/a9d22a0e-928d-4bb4-8525-e38c9481469 ...

  7. Oracle中dbms_random包详解

    Oracle之DBMS_RANDOM包详解参考自:https://www.cnblogs.com/ivictor/p/4476031.html https://www.cnblogs.com/shen ...

  8. winXP 下安装python3.3.2

    1. 安装python-3.3.2 2. 安装setuptools 下载解压后,进入路径 python setup.py install 3.安装pip 下载解压后,进入路径 python setup ...

  9. tomcat 8 内存优化

    在Linux环境下设置Tomcat JVM,在/opt/tomcat/bin/catalina.sh文件中找到"# ----- Execute The Requested Command&q ...

  10. Vue API 3模板语法 ,指令

    条件# v-if# v-if 指令用于条件性地渲染一块内容.这块内容只会在指令的表达式返回 truthy 值的时候被渲染. v-show# v-show 指令也是用于根据条件展示一块内容.v-show ...