HihoCoder - 1339 Dice Possibility(概率dp)

题意:求用N(1<=N<=100)个骰子掷出M(1<=M<=600)的概率

分析:直接求概率可能出现6^100次方,会爆精度。可以用一个数组dp[i][j]记录用i个骰子掷出j的概率。i为0时无论j是多少,概率都是0。i为1时,j从1-6的概率都是1/6。其余可以递推得到

dp[i][j]  = 0 (j<i || j>6*i),sigma(dp[i-1][max(0,j-k)])  (1<=k<=6)

#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int maxn = 1e4+5;
const int INF= 0x3f3f3f3F;
const int mod = 200907;
double dp[105][605];
void pre()
{
    for(int i=1;i<=6;++i) dp[1][i]=(double)(1.0/6);
    for(int i=2;i<=100;++i){
        for(int j=1;j<=600;++j){
            if(j<i) dp[i][j] = 0.0;
            else{
                dp[i][j] =0;
                for(int k=max(1,j-6);k<j;++k){
                    dp[i][j] += 1.0*dp[i-1][k]/6.0;
                }
            }
        }
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
         freopen("in.txt","r",stdin);
         freopen("out.txt","w",stdout);
    #endif
    dp[0][0]=0;
    pre();
    int T,N,M,Q,u,v,tmp,K;
    while(scanf("%d%d",&N,&M)==2){
        printf("%.2f\n",100.0*dp[N][M]);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/xiuwenli/p/9424857.html

时间: 2024-10-10 01:24:37

HihoCoder - 1339 Dice Possibility(概率dp)的相关文章

HihoCoder1339 Dice Possibility(概率DP+母函数)

时间限制: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.3

HDU 4652 Dice (概率DP)

Dice Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0

HDU 4652 Dice(概率dp)

Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0 m n:

Dice (III) 概率dp

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; int t,n; double dp[100010]; int main() { scanf("%d",&t); int cas=1; while(t--) { scanf("%d",&n); dp[n]=0

Light OJ 1248 - Dice (III) 概率DP

n个面的骰子 求每个面至少扔到一次的期望值 设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0] 因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况 所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #include <cstdio> #include <cstring> #define imax 100005

Throwing Dice(概率dp)

C - Throwing Dice Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu LightOJ 1064 uDebug Description n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x? Input Input starts wit

HDU 4599 Dice (概率DP+数学+快速幂)

题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n),这个用DP来推公式,d[i],表示抛 i 次连续的点数还要抛多少次才能完成.那么状态转移方程就是 d[i] = 1/6*(1+d[i+1]) + 5/6*(1+d[1]), 意思就是说在第 i 次抛和上次相同的概率是1/6,然后加上上次抛的和这一次,再加上和上次不同的,并且又得从第1次开始计算. 边界就是

hdu4586 概率dp

http://acm.hdu.edu.cn/showproblem.php?pid=4586 Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equal possibility to show up when one rolls a dice. Each side has an integer ai on it. Now here is a game

hdu--4576--概率dp&lt;见过最简单的概率dp&gt;

看到 expected possibility 一下子 又觉得是概率dp了.. 这题 也的确是了 但做的狠无语啊  尝试了2种  一个是TLE 一个是AC 但也要花掉了3000多ms.. 而且 我也觉得这两种 区别不大啊 思想是一样的 就是处理上有点区别.. 应该是第二种TLE的故意被卡了时间吧  my guess 这题的话 思路很简单 就是一层一层的递推下来 并且这一层的状态只与上一层有关~ 其实 每次可以选择走的方案数就是: 2^1 --> 2^2 --> 2^3 --> .....