求掷骰子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. Linux中的mysql指令

    如何启动/停止/重启MySQL一.启动方式1.使用 service 启动:service mysqld start2.使用 mysqld 脚本启动:/etc/inint.d/mysqld start3 ...

  2. c语言数字图像处理(八):噪声模型及均值滤波器

    图像退化/复原过程模型 高斯噪声 PDF(概率密度函数) 生成高斯随机数序列 算法可参考<http://www.doc.ic.ac.uk/~wl/papers/07/csur07dt.pdf&g ...

  3. MOD 模除运算符

    用于奇数和偶数的校验,星期几的计算,以及其它专门的计算.

  4. 树莓派操控SG90舵机

    目录 舵机接线 PWM介绍 使用PWM控制舵机 这里使用树莓派来操作sg90的舵机.先看一下这个舵机的样子: 这就是传说中的SG90舵机啦,转角是0-180. SG90舵机接线: SG90舵机有三条线 ...

  5. 微信JS-SDK实现上传图片功能

    最近在项目开发中,有一个在微信WEB项目中上传图片的需求,一开始使用了传统的<input type="file">的方式去实现,但是后面发现在使用这种传统模式时会由于手 ...

  6. CocoaPods did not set the base configuration of your project because your project already has a custom config set.

    今天在封装自己的消息推送SDK的时候,pod install 的时候,突然报这个错误,解决方式如下: $ pod install Analyzing dependencies Downloading ...

  7. mysql更新表数据时报错 You can't specify target table 'RES_CATALOG_CLASSIFY' for update in FROM clause

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 将sql语句 UPDATE RES ...

  8. OO终章--总结博客

    一.测试与正确性论证的比较 从方法上看,测试是使用大量测试样例来覆盖测试代码,从而能够检测代码的实现是否正确,功能是否完善.而正确性论证是使用代码的规格和逻辑进行严密的推论和证明,从而验证代码的实现正 ...

  9. java第四次实验报告

    课程:Java程序与设计     班级:1352 姓 名:池彬宁  小组成员: 20135212池彬宁 20135208贺邦 学号:20135212 成绩:             指导教师:娄嘉鹏  ...

  10. C# 打包

    开发环境:VS2010+SQL Server 2008 操作系统:win7_32bit 旗舰版 开发语言:C# 项目名称:学生寄宿管理系统 下面开始介绍:如何给windows应用程序打包? 第一步: ...