hiho一下 第174周

题目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
", dp[n][m] * 100);
    return 0;
}
原文地址:https://www.cnblogs.com/dramstadt/p/7753336.html