UVa 10759 Dice Throwing (概率DP)
来源:互联网 发布:windows whistler 2257 编辑:程序博客网 时间:2024/05/17 00:51
10759 - Dice Throwing
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1700
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 Output for Sample Input
3 9
1 7
24 24
15 76
24 56
24 143
23 81
7 38
0 0
20/27
0
1
11703055/78364164096
789532654692658645/789730223053602816
25/4738381338321616896
1/2
55/46656
从下往上慢慢加~
f[i + 1][j + k] += f[i][j];
完整代码:
/*0.015s*/#include<cstdio>typedef unsigned long long ull;ull f[25][150];ull gcd(ull a, ull b){return b ? gcd(b, a % b) : a;}int main(){int i, j, k, n, x;ull ans, b, g;for (i = 1; i <= 6; ++i)f[1][i] = 1;for (i = 1; i < 25; ++i)for (j = i; j <= 6 * i; ++j)for (k = 1; k <= 6; ++k)f[i + 1][j + k] += f[i][j];while (scanf("%d%d", &n, &x), n){if (x > 6 * n){puts("0");continue;}else if (x <= n){puts("1");continue;}ans = 0, b = 1;for (i = x; i <= 6 * n; ++i) ans += f[n][i];for (i = 0; i < n; ++i) b *= 6;g = gcd(ans, b);printf("%llu/%llu\n", ans / g, b / g);}}
- UVa 10759 Dice Throwing (概率DP)
- UVA 10759 Dice Throwing(dp 概率)
- UVa 10759 - Dice Throwing (概率DP+预处理)
- uva 10759 - Dice Throwing(dp)
- UVA 10759 Dice Throwing
- UVa:10759 Dice Throwing
- uva 10759 Dice Throwing
- UVA - 10759 Dice Throwing
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- Light oj 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
- 10759 - Dice Throwing
- UVA10759 - Dice Throwing(dp+gcd)
- LightOJ 1064 - Throwing Dice (dp)
- lwip中ip层的实现浅析
- 计数排序的分析与实现
- SQLite Exception, Database Already Closed
- 后缀数组
- 为虚函数,什么情况下需要将析构函数定义为虚函数?
- UVa 10759 Dice Throwing (概率DP)
- NSUserDefaults standardUserDefaults的使用
- 下拉列表级联操作
- 嵌入式面试之经典基础题
- 详解数据库设计三大范式
- 关于连接无密码的wifi问题
- 新手的ubuntu学习笔记,持续更新
- 数据库删除重复数据
- 浅谈接口与抽象类