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 |
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)的更多相关文章
- lightoj 1145 - Dice (I)(dp+空间优化+前缀和)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1145 题解:首先只要是dp的值只和上一个状态有关系那么就可以优化一维,然后这题 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- 1193 - Dice (II)
1193 - Dice (II) PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB You h ...
- HDOJ 4652 Dice
期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 三种renderman规范引擎的dice对比
次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...
- ural 1145. Rope in the Labyrinth
1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular f ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
随机推荐
- Vue函数防抖和函数节流
函数防抖(debounce) 应用场景 登录.发短信等按钮避免用户点击太快,以致于发送了多次请求,需要防抖 调整浏览器窗口大小时,resize 次数过于频繁,造成计算过多,此时需要一次到位,就用到了防 ...
- 前端页面存放token
//本地缓存,记录token function set(type, value) { localStorage.setItem(type, value); } function get(type) { ...
- 打破砂锅问到底!HTTP和HTTPS详解
HTTP 引自维基百科HTTP:超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式.协作式和超媒体信息系统的应用层协议.HTTP是万维网的数 ...
- final&static
final 1.final修饰类,那么该类不能有子类,那么也就没有子类重写父类的方法,也就没有多态 2.final修饰成员变量,那么成员变量要么显式赋值(用第一种),要么在构造方法中赋值 无论哪一种, ...
- 神器Tampermonkey的安装使用
Tampermonkey是一款基于浏览器的神奇插件,在国内称为油猴,开发者可以在上面开发满足自己需求的各类浏览器应用脚本.不过经过全球各地无数开发者数年的积累现在其官网已经有一大把的优秀的现成脚本,完 ...
- 一、手把手教你docker搭建fastDFS文件上传下载服务器
在搭建fastDFS文件上传下载服务器之前,你需要准备的有一个可连接的linux服务器,并且该linux服务器上已经安装了docker,若还有没安装docker的,先百度自行安装docker. 1.执 ...
- 【Java基础】transient关键字
1. transient的作用及使用方法 我们都知道一个对象只要实现了Serilizable接口,这个对象就可以被序列化,java的这种序列化模式为开发者提供了很多便利,我们可以不必关系具体序列化的过 ...
- 【C#】【MySQL】C#连接MySQL数据库(一)代码
C#连接MySQL数据库 准备工作 1.环境安装 安装MySQL For Visual Studio<<点击进入官网下载 第一个要下载安装,第二个下载后将MySQL.data添加到Visu ...
- 访问Github速度很慢以及解决方法(系统通用)
原因分析1,CDN,Content Distribute Network,可以直译成内容分发网络,CDN解决的是如何将数据快速可靠从源站传递到用户的问题.用户获取数据时,不需要直接从源站获取,通过CD ...
- socket通道
一.socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 就是两个进程,跨计算机,他俩需要通讯的话,需要通过网络对接起来.这就是 socket 的作 ...