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 ...
随机推荐
- CSS快速入门-鼠标悬浮(hover伪类)
一.概述 hover伪类:在鼠标移到元素上时向此元素添加特殊的样式.比较普通的就是一个url,当你鼠标放上去后,会变颜色. 在现实的应用场景也非常之多.最常见的是网站的悬浮导航,当鼠标放到导航条上时, ...
- zabbix4.0LTS安装配置
一.环境准备 1.最小化安装centos7.5系统 2.安装常用软件包 yum install -y net-tools vim bash-completion 3.关闭selinux和修改主机名 v ...
- c语言数字图像处理(六):二维离散傅里叶变换
基础知识 复数表示 C = R + jI 极坐标:C = |C|(cosθ + jsinθ) 欧拉公式:C = |C|ejθ 有关更多的时域与复频域的知识可以学习复变函数与积分变换,本篇文章只给出DF ...
- centos7 --ngnix 常用命令:
配置命令 随服务器启动 # systemctl enable nginx.service 重启 nginx 服务 # systemctl restart nginx.service 停止 nginx ...
- 分享一篇IBN(Intent-based networking)调研报告
IBN调研报告 背景 SDN(Software-defined network):最大特点在于具有松耦合的控制平面与数据平面.支持集中化的网络状态控制.实现底层网络设施对上层应用的透明.具有灵活的软件 ...
- python编辑选课系统
一.需求分析 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包含,周期,价格,通过学校创建课 ...
- Python20-Day05
一.模块与包 1.模块 什么是模块? 在python中,模块可以分为四个通用类别: 1. 使用python编写的.py文件 2. 已经被编译为共享库或DLL的c或者c++扩展 3. 把一系列模块组织到 ...
- [C#] 取得每月第一天和最後一天、某月总天数
思路: 1. DateTime dt= DateTime.Now; //获取当前时间 eg:2013-09-08 09:25:0 0 2. DateTime dt1 = new DateTime(d ...
- java第二次试验报告
北京电子科技学院(BESTI) 实 验 报 告 课程:Java程序设计 班级:1353 姓名:郭皓 学号:20135327 成绩: 指导 ...
- 用java进行简单的万年历编写
import java.util.Scanner; public class PrintCalendarDemo1 { public static void main(String[] args) { ...