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. iOS常用第三方库大全,史上最全第三方库收集

    下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableVie ...

  2. Spark 2.0 DataFrame map操作中Unable to find encoder for type stored in a Dataset.问题的分析与解决

    转载:http://blog.csdn.net/sparkexpert/article/details/52871000 随着新版本的spark已经逐渐稳定,最近拟将原有框架升级到spark 2.0. ...

  3. Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_2

    在编写获取路径方法前,我们先把角色须要的动画文件载入进来,角色的文件为png 和 plist格式. player1_anim.png.plist             player1_anim.pn ...

  4. HTTP Analyzer过滤器使用

    HTTP Analyzer简单易用,真实抓包居家必备啊,上一次分享了Fiddler的过滤条件,这次介绍下这款软件的过滤,首先按照肯定是按照软件类型分类喽: 1.按照软件过滤: 这样只会显示chrome ...

  5. JavaScript匿名函数与托付

    <1> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- C#匿名函数--& ...

  6. Mysql视图的创建及使用

    视图理解: 视图又叫虚表.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且在引用视图时动态生成. 视 ...

  7. (一)Thymeleaf用法——Thymeleaf简介

    1. thymeleaf认识 参考官方文档(Project version: 3.0.5.RELEASE)   1.1 介绍 Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎,能 ...

  8. 修改EXCEL

    import xlrdfrom xlutils import copy # 先用xlrd模块,打开一个excelbook=xlrd.open_workbook('app_student.xls') # ...

  9. 工作总结 错误 using 块缺少结束字符“}”。请确保此块内的所有“{”都有匹配的“}”字符,并且任何“}”都不会解释为标记。

    页面上 有两个 它会跟标签 匹配的     标准要在同一级别下 什么也不改变 只改变它们位置 就不报错了 总结 @using (Html.BeginForm()) { } 要根据标签位置 匹配  要放 ...

  10. d3系列2--api攻坚战02

    <html> <head> <style type="text/css"> .area{ fill:steelblue; } </styl ...