UVA10759 Dice Throwing概率+DP
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10759 Dice Throwing概率+DP相关的知识,希望对你有一定的参考价值。
n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x?
Input
The input file contains several test cases. Each test case consists two integers n (1 ≤ n ≤ 24) and x (0 ≤ x < 150). The meanings of n and x are given in the problem statement. Input is terminated by a case where n =0 and x =0. This case should not be processed.
Output
For each line of input produce one line of output giving the requested probability as a proper fraction in lowest terms in the format shown in the sample output. All numbers appearing in output are representable in unsigned 64-bit integers. The last line of input contains two zeros and it should not be processed.
Sample Input
3 9
1 7
24 24
15 76
24 56
24 143
23 81
7 38
0 0
Sample Output
20/27
0
1
11703055/78364164096
789532654692658645/789730223053602816
25/4738381338321616896
1/2
55/46656
问题链接:UVA10759 Dice Throwing
问题简述:计算n个骰子(六面体形状),投掷出总和为k时的概率。
问题分析:打表实现。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10759 Dice Throwing */
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 24;
const int X = 150;
LL dp[N + 1][X + 1];
void init()
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= N; i++)
for (int j = 0; j <= X; j++)
if (dp[i - 1][j])
for (int k = 1; k <= 6; k++)
dp[i][j + k] += dp[i - 1][j];
int main()
init();
int n, x;
while (~scanf("%d%d", &n, &x) && (n || x))
if (x <= n)
printf("1\\n");
else
LL res1 = 0, res2 = pow(6, n);
for (int i = x; i <= X; i++)
res1 += dp[n][i];
if (res1 == 0)
printf("0\\n");
else
LL t = __gcd(res1, res2);
printf("%lld/%lld\\n", res1 / t, res2 / t);
return 0;
以上是关于UVA10759 Dice Throwing概率+DP的主要内容,如果未能解决你的问题,请参考以下文章
Throwing Dice LightOJ - 1064 || (勉强能用的)分数类
UVA10940 Throwing cards away II数学规律+约瑟夫环