Throwing Dice(概率dp)
C - Throwing Dice
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
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)的更多相关文章
- LightOJ1064 Throwing Dice(DP)
第一眼以为是概率DP,我还不会.不过看题目那么短就读读,其实这应该还不是概率DP,只是个水水的DP.. dp[n][s]表示掷n次骰子点数和为s的情况数 dp[0][0]=1 dp[i][j]=∑dp ...
- HDU 4599 Dice (概率DP+数学+快速幂)
题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...
- SPOJ Favorite Dice(概率dp)
题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...
- 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 ...
- hdu 4652 Dice 概率DP
思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...
- dice 概率论 概率DP
题目链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=459 找出公式,公式有实际意义,某种情形当 ...
- Light OJ 1317 Throwing Balls into the Baskets 概率DP
n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...
- HDU 3076:ssworld VS DDD(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description One day, s ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
随机推荐
- POJ 1040 Transportation
链接:http://poj.org/problem?id=1040 Transportation Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- block传值以及利用block封装一个网络请求类
1.block在俩个UIViewController间传值 近期刚学了几招block 的高级使用方法,事实上就是利用block语法在俩个UIViewController之间传值,在这里分享给刚開始学习 ...
- 求出数组中所有数字的和&&弹出层效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 系统重装 U盘安装XP操作系统开机出现提示txtsetup.sif怎么办
你的这个问题 是安装xp时把xp做成u盘出现的 原因是xp没有在根本上支持这种安装 到win7后才支持的 解决方法有以下几种 1,刻录成cd 2重新下载xp ghost版的不会出现这个问题 3证实Ul ...
- 微信小程序 - 一种简写方式
// 第一种 isOrder: function() { //code }, // 第二种 isOrders() { //code },
- S4:装饰模式 Decorator
动态的给一个对象添加额外的一些职责,就增加功能而言,比继承更具灵活性. 如果仅有一个ConcreateComponent,也可以让Decorator继承ConcreateComponent来实现装饰功 ...
- Linux vim命令记录
Ndd :删除N行 多行删除 :1,10d ctrl+v ,移动光标,ctrl+i,输入#,esc :移动处均会输入# gg:文档头 G:文档尾 o:下一行,并进入insert模式 O:上一行并输入 ...
- 【Excle数据透视表】如何得到数据透视表中某个汇总行的明细数据
例如: 现在想得到"北京 汇总"的明细数据,该怎么处理呢? 步骤 右键数据透视表任意单元格→数据透视表选项→启用显示明细数据→确定→单击"北京 汇总"行最后一个 ...
- Oracle 日期总结
一.带星期格式 .SELECT to_char(to_date('2014-12-12','yyyy-mm-dd'),'MM-DD (DAY)') FROM DUAL .SELECT to_char( ...
- Spring使用经验之StandardServletMultipartResolver实现文件上传的基本配置
Note:Spring使用版本是4.1.6.RELEASE 1. 在实现了AbstractAnnotationConfigDispatcherServletInitializer的类中重载custom ...