UVA 10759 Dice Throwing(dp 概率)
2013-11-07 22:15
381 查看
Problem A
Dice Throwing
Input: standard input
Output: standard output
Time Limit: 1 second
n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least [b]x?[/b]
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.
of input contains two zeros and it should not be processed.
题意:给定n个骰子和一个x,要求出用这些骰子投出大于等于x的概率。要求最简。
思路:先用dp打表出用n个骰子掷出x的种数,然后就是用gcd约分。
代码:
Dice Throwing
Input: standard input
Output: standard output
Time Limit: 1 second
n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least [b]x?[/b]
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 lineof 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 |
思路:先用dp打表出用n个骰子掷出x的种数,然后就是用gcd约分。
代码:
#include <stdio.h> #include <string.h> const int N = 30; const int X = 155; long long n, x; long long dp [X], zi, mu; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { for (int i = 1; i <= 24; 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]; } } while (~scanf("%lld%lld", &n, &x) && n || x) { mu = zi = 0; for (int i = n; i <= n * 6; i ++) { mu += dp [i]; if (i >= x) zi += dp [i]; } long long num = gcd(mu, zi); if (zi == mu) printf("1\n"); else if (zi == 0) printf("0\n"); else printf("%lld/%lld\n", zi / num, mu / num); } return 0; }
相关文章推荐
- UVa 10759 - Dice Throwing (概率DP+预处理)
- UVa 10759 Dice Throwing (概率DP)
- uva 10759 - Dice Throwing(dp)
- UVA10759 - Dice Throwing(dp+gcd)
- 概率dp - UVA 11021 Tribles
- UVa 11021 - Tribles (概率DP)
- UVA 1637 Double Patience——概率dp
- Uva 1456 - Cellular Network 概率dp
- UVA 11021(概率DP)
- Uva 10081 Tight words (概率DP)
- UVA10759_Dice Throwing
- UVA - 11021 Tribles 概率dp
- UVa 1456 - Cellular Network(概率DP)
- 概率dp UVA 11762 Race to 1
- UVA 10529-Dumb Bones(概率dp)
- 概率DP,递推(麻球繁殖,UVA 11021)
- Uva 1456 - Cellular Network 概率dp
- UVaLive 4731 UVa 1456 - Cellular Network(概率DP 贪心)
- UVa 10828 Back to Kernighan-Ritchie 高斯消元+概率DP
- UVA 11600-Masud Rana(状压,概率dp)