1. 程式人生 > >hiho一下 第174周

hiho一下 第174周

als tdi lin ret double line put stdlib.h with

題目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周