题目大意:

给你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的更多相关文章

  1. lightoj 1064 Throwing Dice

    题意:给你n个骰子,求n个骰子的和不小于x的概率. 刚开始想每给一组数就计算一次~~太笨了- -,看了别人的代码,用dp,而且是一次就初始化完成,每次取对应的数据就行了.WA了好多次啊,首先不明白的就 ...

  2. Light OJ 1317 Throwing Balls into the Baskets 概率DP

    n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...

  3. Throwing Dice LightOJ - 1064 || (勉强能用的)分数类

    Throwing Dice LightOJ - 1064 方法: 设ans[i][j]表示i个骰子点数恰好为j的概率.那么ans[1][1]到ans[1][6]都为1/6. 显然,$ans[i][j] ...

  4. Throwing Dice(概率dp)

    C - Throwing Dice Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Lig ...

  5. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  6. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  7. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  8. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  9. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

随机推荐

  1. java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity

    错误描述:java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with t ...

  2. linq 多条件查询 where 拼接+分页

    首先定义一个静态类 public static class QueryAssembly { /// <summary> /// 返回true /// </summary> // ...

  3. bzoj1260[CQOI2007]涂色paint

    思路:区间dp,用f[i][j]表示区间[i,j]的答案,然后转移即可. #include<iostream> #include<cstdio> #include<cst ...

  4. Percona XtraBackup 备份原理

    前言 Percona XtraBackup(简称PXB)是 Percona 公司开发的一个用于 MySQL 数据库物理热备的备份工具,支持 MySQl(Oracle).Percona Server 和 ...

  5. a标签使用

    1.发起邮件 注意:如果mailto后面同时有多个参数的话,第一个参数必须以“?”开头,后面的参数每一个都以“&”分隔. <a href="mailto:281345774@q ...

  6. 在hyper安装openwrt

    写了长长长一篇文章,结果把标签关了,这篇文章就不见了,草稿箱也没有!!! 只好直接copy原来作者的文章了 下载地址 openwrt image tulip driver 引用 Want to add ...

  7. javascript 写策略模式,商场收银打折优惠策略

    [Decode error - output not utf-8] ----------------------------- 购物清单 方便面 : 100 x 50 = 5000 | 4000 菊花 ...

  8. Android App资源的查找过程分析

    Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...

  9. What is Windows Clustering

    A cluster is a group of independent computer systems, referred to as nodes, working together as a un ...

  10. phpstorm调整背景、字体颜色

    从这个网站(http://phpstorm-themes.com/)下载各类主题的xml文件, 然后将文件放到phpStorm的文件夹中,比如:C:\Users\USERNAME\.PhpStorm2 ...