hihocoder#1339 : Dice Possibility

来源:互联网 发布:换行业 知乎 编辑:程序博客网 时间:2024/06/03 13:53

时间限制: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
思路:d[i][j]表示扔i个骰子点数和为j的概率。d[i][j]+=d[i-1][j-k]*(1/6) (1<=k<=6)。

#include<bits/stdc++.h>using namespace std;double d[101][601];int main(){    int n,m;    scanf("%d%d",&n,&m);    memset(d,0,sizeof d);    d[0][0]=1;    for(int i=1;i<=n;i++)    {        for(int k=1;k<=6;k++)        {            for(int j=m;j>=k;j--)d[i][j]+=d[i-1][j-k]/6;        }    }    printf("%0.2lf\n",d[n][m]*100);    return 0;}