Light OJ 1064 - Throwing Dice
题目大意:
给你n个骰子, 问点数大于等于x的概率是多少?
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ; struct node
{
LL a, b;///分子,分母
bool vis;
node (LL a=,LL b=,bool vis=false): a(a), b(b), vis(vis) {}
}dp[MAXN][MAXN];
LL gcd(LL a, LL b)
{
return b == ?a:gcd(b,a%b);
} node DFS(int n,int x)///n个筛子掷的至少点数为x
{
if(x <= n)
return node(,,true);
if(dp[n][x].vis)
return dp[n][x]; if(n == || x > n*)
return dp[n][x] = node(,,true); dp[n][x] = node(,,true); for(int i=; i<=; i++)
{
node P = DFS(n-, x-i);
P.b *= ;
LL a = dp[n][x].a;
LL b = dp[n][x].b;
LL c = P.a, d = P.b;
if(dp[n][x].b == )
dp[n][x] = P;
else
{
LL e = gcd(b,d);
dp[n][x].a = a*(d/e) + c*(b/e);
dp[n][x].b = b/e*d;
LL k = gcd(dp[n][x].a, dp[n][x].b);
dp[n][x].a /= k;
dp[n][x].b /= k;
}
} return dp[n][x];
} int main()
{
int T, n, x, cas = ;
scanf("%d", &T);
while(T --)
{
scanf("%d %d", &n, &x);
node P = DFS(n, x);
printf("Case %d: ", cas ++);
if(P.a == || P.b == )
printf("%lld\n", P.a);
else
printf("%lld/%lld\n", P.a, P.b);
} return ;
}
Light OJ 1064 - Throwing Dice的更多相关文章
- lightoj 1064 Throwing Dice
题意:给你n个骰子,求n个骰子的和不小于x的概率. 刚开始想每给一组数就计算一次~~太笨了- -,看了别人的代码,用dp,而且是一次就初始化完成,每次取对应的数据就行了.WA了好多次啊,首先不明白的就 ...
- Light OJ 1317 Throwing Balls into the Baskets 概率DP
n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...
- Throwing Dice LightOJ - 1064 || (勉强能用的)分数类
Throwing Dice LightOJ - 1064 方法: 设ans[i][j]表示i个骰子点数恰好为j的概率.那么ans[1][1]到ans[1][6]都为1/6. 显然,$ans[i][j] ...
- Throwing Dice(概率dp)
C - Throwing Dice Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Lig ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
随机推荐
- 【转载】Oracle层次查询和分析函数
摘要 一组连续的数,去掉中间一些数,如何求出剩下的数的区间(即号段)?知道号段的起止,如何求出该号段内所有的数?知道一个大的号段范围和已经取过的号段,如何求出可用的号段?利用Oracle提供的强大的查 ...
- 有理数类 Java BigInteger实现
import java.math.BigInteger; public class Rational extends Number implements Comparable { private Bi ...
- ubuntu 安装 fcitx
安装fcitx (1)添加ppa源 sudo add-apt-repository ppa:fcitx-team/nightly 或 sudo add-apt-repository ppa:fcitx ...
- mssql死锁问题
在网上查看了很多死锁与阻塞的资料,为什么会出现死锁或者阻塞? 阻塞在大数据量的数据库中经常出现,在我现在的其中一个项目出现的频率很高,根据网上查到死锁跟阻塞的资料,当时分析出来,主要是多台设备同时调用 ...
- JavaScript高级程序设计(二):在HTML中使用JavaScript
一.使用<script>元素 1.<script>元素定义了6个属性: async:可选.表示应该立即下载脚本,但不应该妨碍页面中的其他操作,比如下载其他资源或等待加载其他脚本 ...
- Ext.Net学习笔记10:Ext.Net ComboBox用法
ComboBox是最常用的控件之一,它与HTML中的Select控件很像,但可以进行多选.自定义显示格式.分页等. ComboBox用法 <ext:ComboBox runat="se ...
- spring学习笔记之spring框架本质
Spring框架的本质是,开发者在Spring配置文件中使用XML元素进行配置,实际驱动Spring执行相应的代码: 使用<bean.../>元素,实际启动Spring执行无参或有参构造函 ...
- GitCam一款Gif动画制作软件
本篇文章由:http://www.sollyu.com/gitcam-a-gif-animation-software/ 说明 GifCam是一款小巧.免费的录制电脑屏幕并制作成GIF动画的软件,具有 ...
- centOS 多网卡 启动网络 eth0 does not to be present
centOS 6.4 中 em1 就是eth0... ---------------------------------------- http://www.php-oa.com/2012/03/07 ...
- docker私有仓库
1.docker pull registry 2.sudo docker run -d -p 5000:5000 registry 默认情况下,会将仓库存放于容器内的/tmp/registry目录下, ...