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 book用户认证学习

    用户与Authentication 通过session,我们可以在多次浏览器请求中保持数据, 接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们需要 ...

  2. 10 种机器学习算法的要点(附 Python)(转载)

    一.前言 谷歌董事长施密特曾说过:虽然谷歌的无人驾驶汽车和机器人受到了许多媒体关注,但是这家公司真正的未来在于机器学习,一种让计算机更聪明.更个性化的技术 也许我们生活在人类历史上最关键的时期:从使用 ...

  3. USE [EPPM] [dbo].[REFRDEL_CLEANUP]

    USE [EPPM] GO /****** Object: StoredProcedure [dbo].[REFRDEL_CLEANUP] Script Date: 2016/4/2 16:32:29 ...

  4. HDOJ 1534 Schedule Problem 差分约束

    差分约数: 求满足不等式条件的尽量小的值---->求最长路---->a-b>=c----> b->a (c) Schedule Problem Time Limit: 2 ...

  5. Android错误之--Error retrieving parent for item: No resource found that matches the given name &#39;Theme.A

    错误提示:error: Error retrieving parent for item: No resource found that matches the given name 'Theme.A ...

  6. STL学习笔记(变序性算法)

    变序性算法改变元素的次序,但不改变元素值. 这些算法不能用于关联式容器,因为在关联式容器中,元素有一定的次序,不能随意变动. 逆转元素次序 void reverse(BidirectionalIter ...

  7. Windows重装系统

    本文主要针对那些不会重装系统windows的用户,虽然重装系统win7或win10很简单,但是还是有一些小白不明白如何安装新系统,也不清楚有几种安装方式.本教程现在就详细的讲讲利用U盘重装系统的具体步 ...

  8. 【转】Intellij IDEA常用配置详解

    1. IDEA内存优化 先看看你机器本身的配置而配置. \IntelliJ IDEA 8\bin\idea.exe.vmoptions -------------------------------- ...

  9. C#实现发送手机短信

  10. 从两张Excel表所想到的

    从两张Excel表所想到的 前几日,客服妹子发过来几张表,让我给她做下匹配,然后做了,想了,便有了这篇博文,不由感慨,看似简简单单的两张Excel表其实藏着好多东西,记叙如下,与君共勉. 最初的需求: ...