您的位置:首页 > 其它

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: