hiho一下 第174周
2017-10-30 10:11
155 查看
题目1 : Dice Possibility
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
What is possibility of rolling N dice and the sum of the numbers equals to M?
输入
Two integers N and M. (1 ≤ N ≤ 100, 1 ≤ M ≤ 600)
输出
Output the possibility in percentage with 2 decimal places.
样例输入2 10样例输出8.33
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
What is possibility of rolling N dice and the sum of the numbers equals to M?
输入
Two integers N and M. (1 ≤ N ≤ 100, 1 ≤ M ≤ 600)
输出
Output the possibility in percentage with 2 decimal places.
样例输入2 10样例输出8.33
#include<stdio.h> #include<string.h> #include<stdlib.h> double dp[105][605]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n, m; scanf("%d%d", &n, &m); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= 6; i++) { dp[1][i] = 1.0 / 6.0; } for (int i = 2; i <= n; i++) { for (int j = i; j <= 6 * i; j++) { double tmp = 0; for (int k = 1; k <= 6; k++) { tmp += dp[i - 1][j - k]; } tmp /= 6.0; dp[i][j] = tmp; } } printf("%.2lf\n", dp [m] * 100); return 0; }
相关文章推荐
- hiho一下 第174周 - Dice Possibility【概率dp的简单运用 java & c++】
- Dice Possibility hiho一下 第174周
- hiho一下~week_2:从简单匹配—>hash—>trie树
- 编程之美hiho一下求最长回文串的长度
- hiho一下 第167周
- hiho一下 第三十八周 二分·二分答案【二分+bfs】
- Constraint Checker hiho一下第176周
- hiho一下 第十一周——树中的最长路
- hihoCoder - hiho一下 第二十七周 - A - 最小生成树二·Kruscal算法
- hiho一下 第十五周
- 斐波那契数列 改1 3*N 骨牌覆盖 改1 hiho一下 第四十二周 递归不行 矩阵加速
- hiho一下·47 拓扑排序·一(判断是否能够Topo排序)
- hiho一下 第五十周
- hiho一下第二周Trie树 题解
- hiho一下 第159周 区域周长
- hiho一下 第五十八周
- hiho一下 第六十周 题目1 : String Matching Content Length dp 最长公共子序列
- hiho一下 第六十一周 题目1 : Combination Lock 线段树 成段更新
- hiho一下 第二周 trie树
- [hihocoder]hiho一下 第163周 希尔伯特曲线