LightOJ 1064 Throwing Dice
来源:互联网 发布:类似知否的小说 编辑:程序博客网 时间:2024/05/14 07:01
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,要求出用这些骰子投出大于等于x的概率。要求最简。
分析:先预处理算出i个骰子得到的和为j的种数。然后用gcd函数约分。
dp[i+1][j+k]=sigma(dp[i][j]) (1<=k<=6)
#include <cstdio>using namespace std;__int64 dp[25][150];__int64 gcd(__int64 x, __int64 y){ return y ? gcd(y, x % y) : x;}int main(){ __int64 up, down, g; int t, n, x; for (int i = 1; i <= 25; i++){ for (int j = 1; j <= 150; j++){ if (i == 1 && j <= 6) dp[i][j] = 1; for (int k = 1; k <= 6; k++){ if (j >= k) dp[i][j] += dp[i - 1][j - k]; } } } scanf("%d", &t); for (int cas = 1; cas <= t; cas++){ scanf("%d%d", &n, &x); up = 0, down = 0; for (int i = n; i <= n * 6; i++){ down += dp[n][i]; if (x <= i) up += dp[n][i]; } if (up == down) printf("Case %d: 1\n", cas); else if (up == 0) printf("Case %d: 0\n", cas); else{ g = gcd(up, down); printf("Case %d: %lld/%lld\n", cas, up / g, down / g); } } return 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
- shell 之 read
- WebSphere Message Broker介绍
- 【Java】基本类型和引用类型(值传递)
- go语言闭包如何捕获参数
- 那一夜, 我懂了视频帧
- LightOJ 1064 Throwing Dice
- Yii2 模板嵌套用法
- MySQL数据记录基本操作——单表查询
- 欢迎使用CSDN-markdown编辑器
- 函数该传递什么参数
- Linux下安装php加速软件Xcache
- VLAN和SVI是两个不同的概念
- 日经春秋 20160326
- .NET是一个不断完善的框架