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


PROBLEM SETTER: JANE ALAM JAN
思路:和1145差不多。
dp[i][j]表示前i次点数之和为j的数所有对数的各个的乘积之和。
那么dp[i][j]=dp[i-1][j-1]+dp[i-1][j-2]*2+....dp[i-1][j-k]*k;
这样的复杂度是n*n*n;这样是过不了的;
那么dp[i][j+1]=dp[i-1][j]+dp[i-1][j-1]*2+dp[i-1][j-2]*3+....dp[i-1][j-k+1]*k;
那么dp[i][j+1]=dp[i][j-1]+dp[i-1][j-1]+sum[j-2]-sum[max(0,j-1-m)]-dp[i-1][max(0,j-m-1)]*m;
那么我们每次维护一个dp[i][j]的前缀和就可以了。
 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)的更多相关文章

  1. Dice (II) (DP)唉,当时没做出来

    Dice (II) Time Limit: 3000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu [Submit]   [ ...

  2. LightOJ 1248 Dice (III) 概率

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

  3. 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 ...

  4. 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 ...

  5. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  6. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

  7. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. Selenium-IDE在火狐上的扩展

    昨天突然想学学 Selenium,就上网查了一些介绍,发现一些教程基本都是比较老版本的了,使用起来略有不便,所以今天试着写一些最新版本的.请参考Selenium官网.文章以下内容都是在 Mac 机器上 ...

  2. linux 实用指令时间日期类

    linux 使用指令时间日期类 data 显示当前日期 基本语法 date 显示当前时间 date+%Y 显示当前年份 date+%m 显示当前月份 date+%d 显示当前是哪一天 date &qu ...

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

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

  4. C语言大小端判定

    要判定大小端?需要弄清以下几个问题: 1.当一个变量占多个字节时,变量的指针指向的是低地址 2.什么是大小端? 大端模式:是指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中. 小 ...

  5. 零基础学习java------day12------数组高级(选择排序,冒泡排序,二分查找),API(Arrays工具类,包装类,BigInteger等数据类型,Math包)

    0.数组高级 (1)选择排序 它的工作原理是每一次从待排序的数据元素中选出最小(或最大)的一个元素,存放在序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的起始位置 ...

  6. Codeforces Round #754 (Div. 2) C. Dominant Character

    题目:Problem - C - Codeforces 如代码,一共有七种情况,注意不要漏掉  "accabba"  , "abbacca"  两种情况: 使用 ...

  7. Redis的持久化机制:RDB和AOF

    什么是Redis持久化? Redis作为一个键值对内存数据库(NoSQL),数据都存储在内存当中,在处理客户端请求时,所有操作都在内存当中进行,如下所示: 这样做有什么问题呢? 其实,只要稍微有点计算 ...

  8. 查询表名和表备注(中文名) 及 dba_tables、all_tables和user_tables的区别

    1. select a.* from ALL_TAB_COMMENTS a --查表名和表中文名select a.* from ALL_TAB_COLUMNS a --查询表字段属性select a. ...

  9. .NET6使用DOCFX自动生成开发文档

    本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...

  10. Identity Server 4 从入门到落地(十)—— 编写可配置的客户端和Web Api

    前面的部分: Identity Server 4 从入门到落地(一)-- 从IdentityServer4.Admin开始 Identity Server 4 从入门到落地(二)-- 理解授权码模式 ...