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 ...
随机推荐
- .net开发常用的第三方开发组件
转自:http://www.cnblogs.com/damsoft/p/6100323.html .net开发常用的第三方组件: 1.RSS.NET.dll: RSS.NET是一款操作RSS feed ...
- 新人补钙系列教程之:3D理论 - 二进制空间分割(BSP)树
1. 什么是BSP树 BSP算法的初始数据是一个多边形集,BSP在预处理的时候先在多边形集中选取一个多边形作为支持平面,然后根据这个平面将集合划分成两个部分,每个部分是一个新的子节点,递归进行该过程, ...
- oracle闪回flashback_transaction_query知识点
查询更新记录: select t.start_timestamp, t.commit_timestamp, t.logon_user, t.operation, t.table_name, t.tab ...
- agruments应用——求出函数参数的总合&&css函数——设置/读取对象的属性&&当前输入框高亮显
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 最新iOS发布App Store详细图文教程~
网上有很多关于iOS发布上架的教程,但大多比较旧而且不完整.不够清晰.所以整理了一个详细完整的iOS APP发布上架App Store的图文教程.分享给小白到大神路上前进的你我. 上架iOS需要一个苹 ...
- OpenStack二三事(1)
更新系列不是教材,不说教,不讲道理,仅仅记录. OpenStack在云计算领域大热,没有理由不去了解它. 先说说我对OpenStack的感觉,开源.廉价.麻烦.大家都在用,在了解开发流程后.OpenS ...
- 【BIEE】08_修改浏览器标题栏显示内容
打开分析,我们可以看到标题栏中显示的BIEE默认的,现在想要把这个修改为自定义的 打开文件路径: D:\obiee\Oracle_BI1\bifoundation\web\msgdb\l_zh-CN\ ...
- index+small+row+if经典函数组合应用
EXCEL中index+small+row+if 函数组合可以查出满足同一条件的所有记录,通过实例讲解: 本文为原创,转载需标明出处,谢谢! 例:查找出一年级的所有班级及人数: A B C D 1 年 ...
- NSNotification的几点说明
1.NSNotification消息的同步性 ①NSNotification使用的是同步操作.即如果你在程序中的A位置post了一个NSNotification,在B位置注册了一个observer,通 ...
- devpress grid表格自适应列宽的问题
/// <summary> /// 自适应列宽,显示横向滚轴,只有当所有列都已经在界面上加载完成之后才能生效 /// </summary> public void setAut ...