UVA - 10759 Dice Throwing
来源:互联网 发布:linux复制为多个文件 编辑:程序博客网 时间:2024/06/11 18:13
题目大意:给出n和x,计算在丢n个色子,出现的点数大于等于x的概率,要求分式最简。
解题思路:num[i][j] 与num[i][j + 1]中间的增长个数与用i个色子丢出的点数为j的情况有关,然而求用i个色子丢出点数的情况则是非常好求的:num[i][j] = ∑(j + 1 ≤ k ≤ j + 6)num[i][k].
然后就可以进一步的去求丢出i个色子丢出的点数小于x的情况。
#include <cstdio>#include <cstring>long long dp[160][30];long long dfs(long long m, int c) {if (dp[m][c] != -1) return dp[m][c];dp[m][c] = 0;for (int i =1 ; i <= 6; i++)if (m - i > 0)dp[m][c] += dfs(m - i, c + 1);return dp[m][c];}long long gcd(long long a, long long b) {return b == 0 ? a : gcd(b, a % b);}int main() {long long n, m, nu, tmp;while (scanf("%lld%lld", &n, &m), n) {long long de = 1;for (int i = 1; i <= n; i++)de *= 6;memset(dp, -1, sizeof(dp));for (int i = 0; i <= m; i++)dp[i][n] = 1;nu = de - dfs(m, 0);tmp = gcd(de, nu);if (nu == 0)printf("0\n");else if(nu == de)printf("1\n");elseprintf("%lld/%lld\n", nu / tmp, de / tmp);}return 0;}
0 0
- UVA 10759 Dice Throwing
- UVa:10759 Dice Throwing
- uva 10759 Dice Throwing
- UVA - 10759 Dice Throwing
- uva 10759 - Dice Throwing(dp)
- UVa 10759 Dice Throwing (概率DP)
- UVA 10759 Dice Throwing(dp 概率)
- 10759 - Dice Throwing
- UVa 10759 - Dice Throwing (概率DP+预处理)
- Dice Throwing
- D - Throwing Dice
- LightOJ 1064 Throwing Dice
- lightoj 1064 - Throwing Dice
- uva 10759 throw dice
- uva10759 - Dice Throwing(掷骰子)
- LightOJ 1064 Throwing Dice (DP)
- 【LightOJ 1064 】Throwing Dice + dp
- Light oj 1064 Throwing Dice (概率dp)
- file.seek(),file.split(),file,sorted(),file.pop用法
- Android 下拉刷新框架实现
- 【网络协议】互联网协议入门(二)
- linux内存接口函数
- duilib 控件属性列表
- UVA - 10759 Dice Throwing
- Hibernate和Mysql5.5创建表出错——type=InnDB/schema export unsuccessful
- dispatch_queue_t初学
- LA 2666 最短路神题
- Android动画之translate(位移动画)
- AndroidService 深度解析(2)
- 如果我弄个大数据可视化库
- UVA - 138 Street Numbers
- POJ 1751 Highways (Kruskal 最小生成树)