• Dice Possibility


    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 <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #include <ext/rope>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define vi vector<int>
    #define pii pair<int,int>
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    const int maxn=1e3+10;
    const int dis[][2]={0,1,-1,0,0,-1,1,0};
    using namespace std;
    using namespace __gnu_cxx;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m;
    double dp[maxn][maxn];
    int main()
    {
        int i,j,k,t;
        scanf("%d%d",&n,&m);
        rep(i,1,6)dp[1][i]=1.0/6;
        rep(i,2,n)
        {
            rep(j,2,m)rep(k,1,6)
                if(j-k>0)dp[i][j]+=dp[i-1][j-k]/6;
        }
        printf("%.2f
    ",dp[n][m]*100);
        //system("pause");
        return 0;
    }
  • 相关阅读:
    Marriage Match II 【HDU
    Leapin' Lizards [HDU
    稳定婚姻匹配问题
    Sabotage 【UVA
    动态树 学习
    Minimum Cost 【POJ
    Colourful Rectangle【扫描线】
    Get The Treasury【HDU-3642】【扫描线】
    Picture【HDU
    洛谷P1457 城堡 The Castle
  • 原文地址:https://www.cnblogs.com/dyzll/p/5666114.html
Copyright © 2020-2023  润新知