求掷骰子n次,点数之和超过m的概率有多大?分数表示。

两种方法:

1、直接DP。用两个数组分别表示分子和分母,注意计算过程中时时约分。

2、将(x1+x2+x3+x4+x5+x6)n多项式展开,把大于m的幂的系数累加,比上所有项系数的总和就是答案了。这个理解也很容易。

召唤代码君:

#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long ll;
using namespace std; ll f1[][],f2[][];
ll sum1[][],sum2[][];
int n,m; ll gcd(ll A,ll B)
{
return B==?A:gcd(B,A%B);
} ll lcm(ll A,ll B)
{
return A/gcd(A,B)*B;
} int main()
{
f1[][]=f2[][]=sum1[][]=sum2[][]=;
for (int i=; i<; i++)
for (int j=i; j<=i*; j++)//i times score j
{
ll F1=,F2=,FF;
for (int k=max(j-,); k<j; k++)
{
if (f1[i-][k]==) continue;
FF=lcm(F2,f2[i-][k]*);
F1=F1*(FF/F2)+f1[i-][k]*(FF/(f2[i-][k]*));
F2=FF;
FF=gcd(F1,F2);
F1/=FF,F2/=FF;
}
f1[i][j]=F1,f2[i][j]=F2;
if (i==j)
{
sum1[i][j]=f1[i][j],sum2[i][j]=f2[i][j];
continue;
}
FF=lcm(sum2[i][j-],f2[i][j]);
F1=sum1[i][j-]*(FF/sum2[i][j-])+f1[i][j]*(FF/f2[i][j]);
sum1[i][j]=F1,sum2[i][j]=FF;
FF=gcd(sum1[i][j],sum2[i][j]);
sum1[i][j]/=FF,sum2[i][j]/=FF;
} while (scanf("%d%d",&n,&m) && (n|m))
{
if (m<=n) puts("");
else if (m>*n) puts("");
else printf("%lld/%lld\n",sum2[n][m-]-sum1[n][m-],sum2[n][m-]);
} return ;
}

UVA10759_Dice Throwing的更多相关文章

  1. 解决程序出现“terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)”的问题

    最近跑程序时出现了这么一个问题: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_al ...

  2. Throwing cards away I

    Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the top a ...

  3. UVa 10935 - Throwing cards away I (队列问题)

    原题 Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the to ...

  4. lightOJ 1317 Throwing Balls into the Baskets

    lightOJ  1317  Throwing Balls into the Baskets(期望)  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/ ...

  5. UVa---------10935(Throwing cards away I)

    题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 ...

  6. [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...

  7. Debug.Assert vs Exception Throwing(转载)

    来源 Q: I've read plenty of articles (and a couple of other similar questions that were posted on Stac ...

  8. retrofit框架接口调用时候报Throwing new exception

    最近在开发的时候遇到了一个很坑的问题,在三星6.0手机上请求接口时候报了一个异常:Throwing new exception 'length=1658; index=3248' with unexp ...

  9. Throwing cards away I uva1594

     Throwing cards away I Given is an ordered deck of  n  cards numbered 1 to n  with card 1 at the t ...

随机推荐

  1. Unity优化方向——优化Unity游戏中的垃圾回收(译)

    介绍 当我们的游戏运行时,它使用内存来存储数据.当不再需要该数据时,存储该数据的内存将被释放,以便可以重用.垃圾是用来存储数据但不再使用的内存的术语.垃圾回收是该内存再次可用以进行重用的进程的名称. ...

  2. jsp标签在JavaScript中使用时,可能会出现的一个问题。

    直接上代码 <script type="text/javascript"> var E = window.wangEditor; var editor = new E( ...

  3. 解决Ubuntu“下载额外数据文件失败 ttf-mscorefonts-installer”的问题 (转载)

    解决Ubuntu“下载额外数据文件失败 ttf-mscorefonts-installer”的问题 发表于 2017-09-15 | 更新于 2018-04-29 | 分类于 Linux | 评论数: ...

  4. Netty源码分析第8章(高性能工具类FastThreadLocal和Recycler)---->第6节: 异线程回收对象

    Netty源码分析第八章: 高性能工具类FastThreadLocal和Recycler 第六节: 异线程回收对象 异线程回收对象, 就是创建对象和回收对象不在同一条线程的情况下, 对象回收的逻辑 我 ...

  5. Hyperledger Fabric CA User’s Guide——开始(三)

    Fabric CA User’s Guide——开始 先决条件 安装Go 1.9+ 设置正确的GOPATH环境变量 安装了libtool和libtdhl-dev包 下面是在Ubuntu上安装libto ...

  6. 下一代的DevOps服务:AIOps

    AIOps是一个总称,用于指代使用复杂的基础设施管理软件和云解决方案监控工具来实现自动化数据分析和日常的DevOps操作. 那些10年前甚至是5年前构建的系统监控工具的主要缺陷是它们不是为了满足大数据 ...

  7. Codeblocks自动代码格式化快捷键(自带)

    代码区域右击 点format use AStyle 估计也就是考试竞赛逼着用这个

  8. 入门向:南邮CTF_ReadAsm2_WP

    题目链接:http://ctf.nuptzj.cn/challenges#ReadAsm2 我比较菜,所以把思路全部敲上来了. 题目很明确告诉我们,这道题考察阅读汇编代码的能力. 在对编译环境和调用约 ...

  9. tee命令详解

    基础命令学习目录首页 参考:http://man.linuxde.net/tee tee命令用于将数据重定向到文件,另一方面还可以提供一份重定向数据的副本作为后续命令的stdin.简单的说就是把数据重 ...

  10. ftp部署及使用

    常用软件安装及使用目录 http://www.jb51.net/article/106604.htm   ftp部署 本篇文章主要介绍了CentOS7.0下安装FTP服务的方法,小编觉得挺不错的,现在 ...