1193 - Dice (II)
| Time Limit: 3 second(s) | Memory Limit: 32 MB |
You have N dices; each of them has K faces numbered from 1 to K. Now you can arrange the N dices in a line. If the summation of the top faces of the dices is S, you calculate the score as the multiplication of all the top faces.
Now you are given N, K, S; you have to calculate the summation of all the scores.
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) 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: 3 Case 2: 84 Case 3: 74335590 Case 4: 33274428 Case 5: 165 |
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<stdlib.h>
7 #include<queue>
8 using namespace std;
9 typedef long long LL;
10 LL dp[2][15005];
11 const int mod=100000007;
12 LL sum[15005];
13 int main(void)
14 {
15 int i,j,k;
16 scanf("%d",&k);
17 int s;
18 int n,m,c;
19 for(s=1; s<=k; s++)
20 {
21 scanf("%d %d %d",&n,&m,&c);
22 memset(dp,0,sizeof(dp));
23 memset(sum,0,sizeof(sum));
24 for(i=1; i<=m; i++)
25 {
26 dp[1][i]=i;
27 dp[1][i]%=mod;
28 sum[i]=(sum[i-1]+dp[1][i])%mod;
29 }
30 for(i=m+1;i<=c;i++)
31 sum[i]=sum[i-1];
32 for(i=2; i<=n; i++)
33 {
34 int uu=(i)%2;
35 int kk=(i+1)%2;
36 for(j=0; j<i; j++)
37 {
38 dp[uu][j]=0;
39 }
40 for(j=i;j<=c; j++)
41 {
42 dp[uu][j]=((dp[kk][j-1]+dp[uu][j-1])%mod+(sum[j-2]-sum[max(0,j-1-m)])%mod-dp[kk][max(0,j-m-1)]*m%mod)%mod;
43 dp[uu][j]%=mod;
44 dp[uu][j]+=mod;
45 dp[uu][j]%=mod;
46 }
47 for(j=1; j<=c; j++)
48 {
49 sum[j]=sum[j-1]+dp[uu][j];
50 sum[j]%=mod;
51 }
52 }
53 printf("Case %d: ",s);
54 printf("%lld\n",(dp[n%2][c]%mod+mod)%mod);
55 }
56 return 0;
57 }
1193 - Dice (II)的更多相关文章
- Dice (II) (DP)唉,当时没做出来
Dice (II) Time Limit: 3000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu [Submit] [ ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- 统计分析中Type I Error与Type II Error的区别
统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
随机推荐
- 8种Vue中数据更新了但页面没有更新的情况
目录 1.Vue 无法检测实例被创建时不存在于 data 中的 属性 2. Vue 无法检测'对象属性'的添加或移除 3.Vue 不能检测利用数组索引直接修改一个数组项 4.Vue 不能监测直接修改数 ...
- kubectl logs查看日志时出现failed to create fsnotify watcher: too many open files
因为系统默认的 fs.inotify.max_user_instances=128 太小,在查看日志的pod所在节点重新设置此值: 临时设置 sudo sysctl fs.inotify.max_us ...
- 4 — springboot中的jsr303检验
1.导入依赖 <!--JSR303校验的依赖 --> <dependency> <groupId>org.springframework.boot</grou ...
- 银联acp手机支付总结
总结: 1.手机调用后台服务端接口,获取银联返回的流水号tn 银联支付是请求后台,后台向银联下单,返回交易流水号,然后返回给用户,用户通过这个交易流水号,向银联发送请求,获取订单信息,然后再填写银行卡 ...
- weak和拷贝
weak/拷贝 1. weak 只要没有strong指针指向对象,该对象就会被销毁 2. 拷贝 NSString和block用copy copy语法的作用 产生一个副本 修改了副本(源对象)并不会影响 ...
- shell获取目录下(包括子目录)所有文件名、路径、文件大小
一例shell脚本:取得目录下(包括子目录)所有文件名.路径与文件大小. 代码,shell脚本: lsdir.sh #!/bin/bash # #site: www.jquerycn.cn funct ...
- HashMap、ConcurrentHashMap对比
1.hashmap的put的原理,hashmap的扩容及计算槽的算法,线程安全的hashtable.ConcurrentHashMap的区别是什么 1.1 hashMap的put原理 什么时候变成红黑 ...
- java代码从出生到执行的过程浅析
阅读<深入理解java虚拟机 第二版 JVM高级特性与最佳实践> - jdk版本为1.6 1.什么是编译型语言.解释型语言 解释型语言:源代码不是直接翻译成机器语言,而是先翻译成中间代码, ...
- 【C/C++】学生排队吃饭问题
问题: 有n个学生,学生们都在排队取餐,第个学生在L国时刻来到队尾,同一时刻来的学生编号小的在前,每个时刻当队列不为空时,排在队头的同学就可以拿到今天的中餐并离开队伍,若第个学生R团时刻不能拿到中餐, ...
- 莫烦python教程学习笔记——validation_curve用于调参
# View more python learning tutorial on my Youtube and Youku channel!!! # Youtube video tutorial: ht ...