Dice Possibility

What is possibility of rolling N dice and the sum of the numbers equals to M?

Input

Two integers N and M. (1 ≤ N ≤ 100, 1 ≤ M ≤ 600)

Output

Output the possibility in percentage with 2 decimal places.

Sample Input

2 10

Sample Output

8.33

题意: n 个骰子掷出 m 点的概率
简单概率dp
 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 
 5 double dp[105][605]; //i 个骰子掷出 j 的情况
 6 
 7 void Init()
 8 {
 9     dp[0][0]=1;
10     for (int i=1;i<=100;i++)
11     {
12         for (int j=i*1;j<=i*6;j++)
13         {
14             for (int k=1;k<=6;k++)
15                 if (j-k>=0)
16                     dp[i][j]+=dp[i-1][j-k]*1.0/6;
17         }
18     }
19 }
20 
21 int main()
22 {
23     Init();
24     int n,m;
25     while (scanf("%d%d",&n,&m)!=EOF)
26     {
27         printf("%.2lf
",dp[n][m]*100);
28     }
29     return 0;
30 }
View Code
 
原文地址:https://www.cnblogs.com/haoabcd2010/p/6748161.html