描述

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. log4net工作原理(2)

    上回说道:Repository可以说成基于一个log4net配置节创建的log4net容器,它根据log4net配置节的指示创建其他所有对象(Logger/Appender/Filter/Layout ...

  2. MariaDB 数据库迁移

    一.为什么要迁移 我的七月小说站点放在JCloud上,恕我直言,配合我的Aliyun服务器进行数据交互,那是相当的慢,没办法,京东云上面十几块钱的公网ip,也就这样了. 所以我决定把web服务器和数据 ...

  3. 使用Linq读取资源文件

    ResXResourceReader resxr = new ResXResourceReader(txt_WebResourceOpenFile.Text); IEnumerable<Dict ...

  4. 华硕X550VC安装ubuntu后wifi无法连接问题

    在网上找了很多资料比如重新编译内核,想办法连上有线网络然后更新驱动,下载离线驱动安装包…… 等等方法 其中有些方法实际测试的时候失败了,文章是几年前的,可能缺少某些依赖.上个网都这么麻烦实在让人疲惫. ...

  5. 上课总结-数据结构c++

    class 1 数据结构就是指 按一定的逻辑结构组成的一批数据,使用某种存储结构将这批数据存储于计算机中,并在这些数据上定义了一个运算集合. 例1.煤气管道的铺设问题.如图需为城市的各小区之间铺设煤气 ...

  6. mysqldump备份以tmp_开头的表

    需要备份warehouse这个DB下所有以tmp_开头的表名.直接说结论: mysqldump .sql.gz 其中:-Bse是为了将查询中的-----------------等分隔符给屏蔽了. gz ...

  7. kali linux之edb--CrossFire缓冲区溢出

    漏洞的罪恶根源------变量,数据与代码边界不清,开发人员对用户输入没做过滤,或者过滤不严 如这个脚本,写什么,显示什么,但是加上:,|,&&,后面加上系统命令,就执行命令了 缓冲区 ...

  8. 【ARC083E】Bichrome Tree 树形dp

    Description 有一颗N个节点的树,其中1号节点是整棵树的根节点,而对于第ii个点(2≤i≤N)(2≤i≤N),其父节点为PiPi 对于这棵树上每一个节点Snuke将会钦定一种颜色(黑或白), ...

  9. 【bzoj5093】 [Lydsy1711月赛]图的价值 组合数+斯特林数+NTT

    Description "简单无向图"是指无重边.无自环的无向图(不一定连通). 一个带标号的图的价值定义为每个点度数的k次方的和. 给定n和k,请计算所有n个点的带标号的简单无向 ...

  10. Docker安装FastDFS

    什么是FastDFS? FastDFS 是用 c 语言编写的一款开源的分布式文件系统.FastDFS 为互联网量身定制, 充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用 ...