UVA10759_Dice Throwing
求掷骰子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的更多相关文章
- 解决程序出现“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 ...
- 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 ...
- 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 ...
- lightOJ 1317 Throwing Balls into the Baskets
lightOJ 1317 Throwing Balls into the Baskets(期望) 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/ ...
- 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 ...
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...
- Debug.Assert vs Exception Throwing(转载)
来源 Q: I've read plenty of articles (and a couple of other similar questions that were posted on Stac ...
- retrofit框架接口调用时候报Throwing new exception
最近在开发的时候遇到了一个很坑的问题,在三星6.0手机上请求接口时候报了一个异常:Throwing new exception 'length=1658; index=3248' with unexp ...
- 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 ...
随机推荐
- (转)为什么所有浏览器的user-agent都是Mozilla
最早的时候有一个浏览器叫NCSA Mosaic,把自己标称为NCSA_Mosaic/2.0 (Windows 3.1),它支持文字显示的同时还支持图片,于是Web开始好玩起来. 然后出现了一个新的网页 ...
- Spring是什么?优点是什么?
大部分项目都少不了Spring的身影,为什么大家对他如此青睐,而且对他的追捧丝毫没有减退之势呢 Spring是什么: Spring是一个轻量级的DI和AOP容器框架. 说它轻量级有一大部分原因是相对与 ...
- 用xpo实现dc技术的关键点-XPO是如何处理接口类型与真实类型的对应关系的
https://www.devexpress.com/Support/Center/Question/Details/Q487000/xpodatamodel-and-model-interfaces ...
- kali 2018.1安装教程
00x01 摘要 Kali-linux系统,渗透测试人员的利器,其官网自称 OurMost Advanced Penetration Testing Distribution, Ever. 永远是最 ...
- Android studio Error occurred during initialization of VM 问题解决
最近开发导入其他Android项目遇见的问题,如下图: 解决办法: 将org.gradle.jvmargs=的值该为521(堆内存分配过高导致) 备忘,希望能帮助到大家
- centos7以上安装python3,一条命令搞定。
直接复制下面的命令就搞定 yum install python34 python34-pip python34-setuptools 使用方法: python3 ---.py pip3 install ...
- kafka consumer demo
kafka消费者demo pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmln ...
- Bootstrap学习--栅格系统
响应式布局页面:即同一套页面可以兼容不同分辨率的设备. Bootstrap依赖于栅格系统实现响应式布局,将一行均分为12个格子,可以指定元素占几个格子. 实现过程 1.定义容器,相当于之前的table ...
- bash登录过程 其实还不太了解,先码后看
在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile. ~/.bash_login或 ~/.profile文件中的其中一个,执行的顺序 ...
- final文案+美工展示
作业要求:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1438 团队介绍:thunder 组成员及各位博客地址: 1.王航:htt ...