首页 > 其他 > 详细

hiho一下 第174周

时间:2017-10-30 13:19:24      阅读:250      评论:0      收藏:0      [点我收藏+]

题目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[n][m] * 100);
    return 0;
}

 

hiho一下 第174周

原文:http://www.cnblogs.com/dramstadt/p/7753336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!