描述

In the game of Dungeons & Dragons, players often roll multi-sided dice to generate random numbers which determine the outcome of actions in the game. These dice come in various flavors and shapes, ranging from a 4-sided tetrahedron to a 20-sided isocahedron. The faces of an n-sided die, called dn for short, are numbered from 1 to n. Ideally, it is made in such a way that the probabilities that any of its n faces shows up are equal. The dice used in the game are d4, d6, d8, d10, d12, and d20.
When
generating random numbers to fit certain ranges, it is sometimes
necessary or desirable to roll several dice in conjunction and sum the
values on their faces. However, we may notice that although different
combinations of dice yield numbers in the same range, the probabilities
of rolling each of the numbers within the range differ entirely. For
example, a d6 and a d10 afford a range of 2 to 16 inclusive, as does two
d8s, but the probability of rolling a 9 differs in each circumstance.
Your task in this problem is to determine the probability of rolling a certain number, given the set of dice used.

输入

The
input test file will contain multiple cases, with each case on a single
line of input. The line begins with an integer d (where 1 ≤ d ≤ 13),
the number of dice rolled. Following are d descriptors of dice, which
can be any of “d4”, “d6”, “d8”, “d10”, “d12”, or “d20”. The last number
on each line is an integer x (where 0 ≤ x ≤ 1000), the number for which
you are to determine the probability of rolling with the given set of
dice. End-of-input is marked by a single line containing 0; do not
process this line.

输出

For
each test case, output on a single line the probability of rolling x
with the dice, accurate to five decimal places. Note that even if there
trailing zeros, you must show them (see Test problem for an example of
decimal formatting).

样例输入

1 d10 5
2 d6 d6 1
2 d10 d6 9
2 d8 d8 9
0

样例输出

0.10000
0.00000
0.10000
0.12500 题意:求几个筛子相加==x的概率,母函数问题。
#include <stdio.h>
#include <string.h>
#define MAXN 13001 __int64 a[MAXN],b[MAXN];
int d[];
int main(int argc, char *argv[])
{
__int64 n,k,all;
while(scanf("%I64d",&n)!=EOF && n){
all=;
for(int i=; i<=n; i++){
scanf("%d%d",&d[i]);
all*=d[i];
}
scanf("%I64d",&k);
a[]=;
__int64 sum=,sum1;
for(int i=; i<=n; i++){
sum1=sum+d[i];
memset(b,,sizeof(__int64)*(sum1+));
for(int j=; j<=sum; j++){
for(int k=;k<=d[i]; k++){
b[j+k]=b[j+k]+a[j];
}
}
memcpy(a,b,sizeof(__int64)*(sum1+));
sum=sum1;
}
printf("%.5lf\n",double(a[k])/all);
}
return ;
}

TOJ 3488 Game Dice的更多相关文章

  1. HDOJ 4652 Dice

      期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  3. 三种renderman规范引擎的dice对比

    次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...

  4. LightOJ 1248 Dice (III) 概率

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

  5. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  6. 概率 Gym 100502D Dice Game

    题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...

  7. HDU 5955 Guessing the Dice Roll

    HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...

  8. UVALive 7275 Dice Cup (水题)

    Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...

  9. HDU 4586 A - Play the Dice 找规律

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

随机推荐

  1. delphi json用法

    用法:uses Superobject, Sperjsondelphi里有json单元. procedure TForm2.SuperObjectClick(Sender: TObject); var ...

  2. angular 响应式表单

  3. 从头开始学eShopOnContainers——Visual Studio 2017环境配置

    一.安装和配置Docker环境 1.安装Docker CE for Windows 从官方网站下载并安装,https://docs.docker.com/docker-for-windows/inst ...

  4. 一条命令深度清理你的mac

    一条命令深度清理你的mac mac 用了一段时间后很快发现硬盘空间不够了,就想找一些磁盘清理的工具,但是发现居然都是收费的. 就手工操作吧.方法其实非常简单. 就一条命令, cd / du -hd 5 ...

  5. 「BZOJ 2152」聪聪可可

    题目链接 戳这 \(Solution\) 这道题看起来就像点分治对吧.没错就是点分治. 什么是点分治 如果你不会点分治,可以去看看这儿 现在看到这里,首先确保你已经会了点分治,如果不会你还往下看,听不 ...

  6. C# 抽象

    好多人将抽象类也作为多态的一种,其实我觉得并不是特别的好. 抽象在C#中是类的一种表现. 如果将类作为多态,那么前面所有的东西不就白费了吗? C#的 抽象很简单. 那就是抽象. 基本就是高度抽象. 那 ...

  7. 查看Eclipse版本号的方法及各个版本区别 Eclipse选择标准

    这篇文章主要介绍了查看Eclipse版本号的方法及各个版本区别 Eclipse选择标准,方便初学者选择适合自己的版本,需要的朋友可以参考下 Eclipse 是一个开放源代码的.基于Java的可扩展开发 ...

  8. servlet 核心技术

    servlet 核心技术 servlet 生命周期 在 servlet 生命周期中,servlet 容器完成加载 servlet 类和实例化一个 servlet 实例,并通过3个方法来完成生命周期中的 ...

  9. luoguP4396 [AHOI2013]作业

    https://www.luogu.org/problemnew/show/P4396 简单的莫队+树状数组,但博主被卡常了,不保证代码在任何时候都能AC #include <bits/stdc ...

  10. kill 进程的一些小细节

    终止前台进程,可以用Ctrl+C组合键.但对于后台进程需要用kill命令. kill PID 还可以加信号(参数),默认情况下是编号为15的信号.term信号将终止所有不能捕捉该信号的进程. -s 可 ...