C - Throwing Dice

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

LightOJ 1064 uDebug

Description

n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x?

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each test case contains two integers n (1 ≤ n < 25) and x (0 ≤ x < 150). The meanings of n and x are given in the problem statement.

Output

For each case, output the case number and the probability in 'p/q' form where p and q are relatively prime. If q equals 1 then print p only.

Sample Input

7

3 9

1 7

24 24

15 76

24 143

23 81

7 38

Sample Output

Case 1: 20/27

Case 2: 0

Case 3: 1

Case 4: 11703055/78364164096

Case 5: 25/4738381338321616896

Case 6: 1/2

Case 7: 55/46656

//比赛没看懂题,这是一个简单概率dp,第一行是案例数 T ,然后 n , m 是n个骰子掷出至少为 m 的概率。

dp[i][j]代表 i 个骰子,掷出 j 种数

dp[i][j]=SUM(dp[i-1][j-k]) (1<=k<=6)

 #include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define LL long long int n,x;
LL dp[][]; LL gcd(LL x,LL y)
{
return y?gcd(y,x%y):x;
} void Init()
{
for(int i=;i<=;i++)//一个骰子
dp[][i]=;
for(int i=;i<;i++)
{
for (int j=i;j<=*i;j++)//i个骰子所有的点数
{
for (int k=;k<=;k++)
{
if (j-k>=)
dp[i][j]+=dp[i-][j-k];
}
}
}
} int main()
{
Init();
int T;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
scanf("%d%d",&n,&x);
if(x>n*)
{
printf("Case %d: 0\n",cas);
continue;
}
if(x<=n)
{
printf("Case %d: 1\n",cas);
continue;
}
LL up=,down=,g;
for(int i=x;i<=n*;i++)
up+=dp[n][i];
for(int j=;j<n;j++) down*=;
g=gcd(up,down);
printf("Case %d: %lld/%lld\n",cas,up/g,down/g);
}
return ;
}

Throwing Dice(概率dp)的更多相关文章

  1. LightOJ1064 Throwing Dice(DP)

    第一眼以为是概率DP,我还不会.不过看题目那么短就读读,其实这应该还不是概率DP,只是个水水的DP.. dp[n][s]表示掷n次骰子点数和为s的情况数 dp[0][0]=1 dp[i][j]=∑dp ...

  2. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  3. SPOJ Favorite Dice(概率dp)

    题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...

  4. hdu 4599 Dice 概率DP

    思路: 1.求f[n];dp[i]表示i个连续相同时的期望 则 dp[0]=1+dp[1]     dp[1]=1+(5dp[1]+dp[2])/6     ……     dp[i]=1+(5dp[1 ...

  5. hdu 4652 Dice 概率DP

    思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...

  6. dice 概率论 概率DP

    题目链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=459 找出公式,公式有实际意义,某种情形当 ...

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

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

  8. HDU 3076:ssworld VS DDD(概率DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description   One day, s ...

  9. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

随机推荐

  1. django静态html中做动态变化

    在搭建网站中经常有筛选分类的需求 在django中为了简便,我们经常将某些相同部分的内容取出来单独存放形成一个base模板,其他的template继承这个base就可以使用其中的内容 但是这些相同的部 ...

  2. Oracle数据库实现获取前几条数据的方法

    如何在Oracle数据库中实现获取前几条数据的方法呢?就是类似SQL语句中的SELECT TOP N的方法.本文将告诉您答案,举例说明了哟!   1.在Oracle中实现SELECT TOP N : ...

  3. 蓝的成长记——追逐DBA(5):不谈技术谈业务,恼人的应用系统

    ***************************************声明*************************************** 个人在oracle路上的成长记录,当中 ...

  4. 使用终端shell命令批量改动一个文件下的全部文件的读写权限

    之前对openfire安装的目录就遇到过这个问题,今天再次遇到.须要改动一个目录以下的全部子目录以及文件的三个权限:本用户读写.管理员读写.全部人读写,三个都要需改为wr 步骤例如以下:比如我要改动/ ...

  5. mother&#39;s day.py 母亲节

    今天母亲节,写了个程序.抓取一个站点的母亲节祝福短信.实现自己主动翻页, 道友们也能够甲乙改造.比方加上节日简洁,time()模块. . . 一起分享吧 # -*- coding: cp936 -*- ...

  6. Recycling Settings for an Application Pool <recycling>

    Overview The <recycling> element contains configuration settings that control the conditions t ...

  7. Android开发之Serializable 和 Parcelable的差别(源码分享)

    android 中自己定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable. 一 序列化原因: 1.永久性保存对象.保存对象的字节序列到本地文件里. 2.通过 ...

  8. 会话管理之Cookie技术

    会话管理是web开发中比较重要的环节,这一节主要总结下会话管理中的cookie技术. 1. 何为会话 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个 ...

  9. Java编程手冊-Collection框架(上)

    该文章所讲内容基本涵盖了Collection里面的全部东西,尽管基于jdk 1.5的.可是思路非常清晰 1.引言 1.1 Collection框架的介绍 尽管我们能够使用数组去存储具有同样类型的元素集 ...

  10. linux watch命令

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...