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 ...
随机推荐
- Python爬虫之HTTP和HTTPS
一:HTTP和HTTPS HTTP协议(HyperText Transfer Protocol,超文本传输协议):是一种发布和接收 HTML页面的方法,以明文的形式传输,效率高,但是不安全 HTTPS ...
- C语言 知识点总结完美版
本文采用思维导图的方式撰写,更好的表述了各知识点之间的关系,方便大家理解和记忆.这个总结尚未包含C语言数据结构与算法部分,后续会陆续更新出来,文中有漏掉的知识点,还请大家多多指正. 总体上必须清楚的: ...
- Jenkins管理插件(备份插件)
Jenkins管理插件 为了让所有的插件在 Jenkins 内可用,所有插件的列表可以访问链接 − https://wiki.jenkins-ci.org/display/JENKINS/Plugin ...
- SpringCloud 学习(二) :服务注册与发现Eureka
Spring Cloud应用中可以支持多种的服务治理框架,比如Eureka.Consul.Zookeeper等,现在我们用的是consul,本文以SpringCloud Dalston.SR5版本介绍 ...
- MD5加密简单使用
MD5加密简单使用规则 先写一个加密的工具类吧! public class MD5Util { public static String encoderPassword(String s) throw ...
- HTML基础范例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python所遇到的坑
我是在ubuntu中,自带的有python2,python3有安装了anaconda套件,所以python的版本很多,曾经想删除过不用的python. 先执行 sudo apt remove pyth ...
- 部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener【转】
部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...
- 第十周psp作业
本周psp 本周进度条 代码累积折线图 博文字数累积折线图 饼状图
- github基础操作
1.最简单实用的操作 更新远程仓库 git status git add . git commit -m "add" git push #git push -u origin ma ...