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 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
随机推荐
- 【Redis】过期键删除策略和内存淘汰策略
Redis 过期键策略和内存淘汰策略 目录 Redis 过期键策略和内存淘汰策略 设置Redis键过期时间 Redis过期时间的判定 过期键删除策略 定时删除 惰性删除 定期删除 Redis过期删除策 ...
- A Child's History of England.48
A few could not resolve to do this, but the greater part complied. They made a blazing heap of all t ...
- 【leetcode】337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- 【leetcode】834. Sum of Distances in Tree(图算法)
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are ...
- [学习总结]8、android 自定义控件 使用declare-styleable进行配置属性(源码角度)
declare-styleable:declare-styleable是给自定义控件添加自定义属性用的. 官方的相关内部控件的配置属性文档:http://developer.android.com/r ...
- zabbix之源码安装
#:官网地址 https://www.zabbix.com/documentation/4.0/zh/manual/installation/install #:解压并创建用户 root@ubuntu ...
- web前段canvasjs图表制作一
关于web图表制作的方法有很多种,大家可以去网上这里我就介绍我经常使用的一种方法CanvasJS,这也是一款非常容易掌握并且好用的一种方法. 首先可以去网上下载canvasjs.js插件.下载路径:h ...
- maven依赖对zookeeper的版本冲突问题
我用的是springcloudAlibaba+zookeeper zookeeper下载后 1,修改配置文件,conf目录下的zoo_sample.cfg修改为zoo.cfg. 2,打开zoo.cfg ...
- centos配置 显示中文
目录 一.简介 二.操作 一.简介 不显示中文,出现这个情况一般是由于没有安装中文语言包,或者设置的默认语言有问题导致的. 二.操作 1.查看当前系统语言 登陆linux系统打开操作终端之后,输入 e ...
- LeetCode 36. Valid Sudoku (Medium)
题目 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according ...