lightoj 1064 - Throwing Dice
来源:互联网 发布:免费可视化数据软件 编辑:程序博客网 时间:2024/05/27 14:14
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
Output for Sample Input
7
3 9
1 7
24 24
15 76
24 143
23 81
7 38
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
这题的大意是给你n个骰子,问你掷出不小于x的概率是多少。
因为所有点数的个数是6^n,所以只用求出不小于x的种数有多少个就可以了。
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define inf 1e9#define LL long longusing namespace std;LL dp[30][160];LL gcd(LL a,LL b){ if(b == 0) return a; else return gcd(b,a%b);}int main(void){ int T,n,x,i,j,k; scanf("%d",&T); int cas = 1; while(T--) { scanf("%d%d",&n,&x); memset(dp,0,sizeof(dp)); dp[0][0] = 1; LL sum = 1; for(i=1;i<=n;i++) { sum *= 6; for(j=1;j<=i*6;j++) { for(k=1;k<=6;k++) { if(j < k) break; dp[i][j] += dp[i-1][j-k]; } } } LL ans = 0; for(i=x;i<=n*6;i++) ans += dp[n][i]; printf("Case %d: ",cas++); if(ans == 0) { printf("0\n"); continue; } if(ans == sum) { printf("1\n"); continue; } LL t = gcd(ans,sum); printf("%lld/%lld\n",ans/t,sum/t); }}
0 0
- LightOJ 1064 Throwing Dice
- lightoj 1064 - Throwing Dice
- LightOJ 1064 Throwing Dice (DP)
- 【LightOJ 1064 】Throwing Dice + dp
- LightOJ 1064 Throwing Dice 概率DP
- LightOJ 1064 - Throwing Dice (dp)
- LightOJ 1064 - Throwing Dice(概率DP)
- LightOj 1064 Throwing Dice(概率dp)
- lightoj 1064 - Throwing Dice 简单DP
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- LightOJ 1064 Throwing Dice(724ACM比赛)解析
- 【LightOJ】1064 - Throwing Dice(dp打表)
- Dice Throwing
- Light oj 1064 Throwing Dice (概率dp)
- Light OJ 1064 Throwing Dice(简单DP)
- 10759 - Dice Throwing
- D - Throwing Dice
- UVA 10759 Dice Throwing
- 面向对象程序设计上机练习一(函数重载)
- 项目开发时的编码选择,utf-8还是gb2312
- 解决数据错位:同步方法
- L1-001. Hello World-PAT团体程序设计天梯赛GPLT
- C/C++之for(;;)与while(1)的区别
- lightoj 1064 - Throwing Dice
- Java Se基础篇第二部分--面向对象
- String、StringBuffer与StringBuilder的区别
- Android音频系统之三AudioTrack
- 光纤中的非线性光学效应
- 第十二章 课后练习第2题
- myeclipse中debug启动服务器总是进入debug界面怎么改
- 2016.9.5-9.9
- L1-002. 打印沙漏-PAT团体程序设计天梯赛GPLT