HDU 3076 ssworld VS DDD(概率dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3076

Problem Description

One day, sssworld and DDD play games together, but there are some special rules in this games.

They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1, P2 <= 6). Small number who, whose HP to reduce 1, the same points will remain unchanged. If one of them becomes 0 HP, he loses.

As a result of technical differences between the two, each person has different probability of throwing 1, 2, 3, 4, 5, 6. So we couldn’t predict who the final winner.

Input

There are multiple test cases.

For each case, the first line are two integer HP1, HP2 (1 <= HP1, HP2 <= 2000), said the first player sssworld’s HP and the second player DDD’s HP.

The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end.

Output

One float with six digits after point, indicate the probability sssworld won the game.

Sample Input

5 5
1.000 0.000 0.000 0.000 0.000 0.000
0.000 0.000 0.000 0.000 0.000 1.000
5 5
0.000 0.000 0.000 0.000 0.000 1.000
1.000 0.000 0.000 0.000 0.000 0.000

Sample Output

0.000000
1.000000

Source

2009 Multi-University Training Contest 17 - Host
by NUDT

题意:

有A、B个人分别有H1 H2的血量,他们轮流的扔骰子,仍的点数小的减一血,

若仍的点数一样则都不变,谁先到减0, 谁输,问A赢的概率。

代码如下:

#include <cstdio>
#include <cstring>
double dp[2017][2017];
//dp[i][j]表示A胜j次,B胜i次的概率。
int main()
{
    int n, m;
    double a[7], b[7];
    while(~scanf("%d%d",&m,&n))
    {
        memset(dp,0,sizeof(dp));
        double p1 = 0, p2 = 0, p = 0;
        //设p1,p2,p表示A赢,B赢,两者平局。
        for(int i = 1; i <= 6; i++)
        {
            scanf("%lf",&a[i]);
        }
        for(int i = 1; i <= 6; i++)
        {
            scanf("%lf",&b[i]);
        }
        for(int i = 2; i <= 6; i++)//A赢
        {
            for(int j = 1; j < i; j++)
            {
                p1+=a[i]*b[j];
            }
        }
        for(int j = 2; j <= 6; j++)//B赢
        {
            for(int i = 1; i < j; i++)
            {
                p2+=a[i]*b[j];
            }
        }
        double w1, w2;
        //w1,w2表示整个过程之中赢一局的概率
        p = 1-p1-p2;
        if(p == 1)
        {
            w1 = 0;
            w2 = 0;
        }
        else
        {
            w1 = p1/(1-p);
            w2 = p2/(1-p);
        }
        dp[0][0] = 1;
        for(int j = 0; j < m; j++)
        {
            for(int i = 0; i <= n; i++)
            {
                if(j > 0)
                    dp[i][j]+=dp[i][j-1]*w1;
                if(i > 0)
                    dp[i][j]+=dp[i-1][j]*w2;
            }
        }
        double maxx = 0;
        for(int i = 0; i < n; i++)
        {
            maxx+=dp[i][m-1]*w1;
        }
        printf("%.6lf\n",maxx);
    }
    return 0;
}
时间: 2024-11-03 21:36:07

HDU 3076 ssworld VS DDD(概率dp)的相关文章

hdu 3076 ssworld VS DDD (概率dp)

///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次p0*p1 三次 p0^2*p1,即A赢的概率为p1+p*p1+p^2*p1+...p^n*p1,n->无穷 ///即a_win=p1/(1-p);b_win=p2/(1-p); ///dp[i][j]表示a赢了j次,b赢了i次的概率 ///dp[i][j]=dp[i-1][j]*b_win+dp[

HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2

http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所以设psc为胜率,pls为负率,peq为平率, 则在每一局中的胜率负率平率可以确定, 而在有结果的一个阶段中的胜率和负率则各是一个无穷级数 psc(new)=1*psc+peq*psc+peq*peq*psc.......=lim(n->正无穷)(1-peq^n)*psc/(1-peq)=psc/(

HDU3076 ssworld VS DDD概率DP

kao,WA了那么多次这题目数据是错的,两个人的血量弄错了,输入的 A的血量其实是B的,输入B的其实是A的,由于有平局现象的干扰,所以一开始先把平局包括进去 的 A赢的概率B赢的概率都算出来,然后减去以后就是平局的概率,再在已经除去平局的情况里 算一下A赢的概率,B赢得概率计算出来,这样就可以计算了, 假设方程dp[i][j]代表 A赢了j次B赢了i次的概率,然后状态转移就比较简单了 : dp[i][j] += dp[i][j - 1] * a_win; dp[i][j] += dp[i - 1

HDU 4865 Peter&#39;s Hobby --概率DP

题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实在这里直接DP就可以了 定义:dp[i][j]为第i天天气为j(0,1,2分别表示三个天气)的概率,path[i][j]记录路径,path[i][j] = k 意思是前一天天气为k时,这一天有最大的概率是天气j. 做一个三重循环,对于每天,枚举今天的天气,再在里面枚举昨天的天气,则有: dp[i][

HDU 4405 Aeroplane chess (概率DP求期望)

题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点需要步数的期望 其中有m个跳跃a,b表示走到a点可以直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点可以到走到i+1,i+2,i+3,i+4,i+5,i+6 点且每个点的概率都为1/6 所以dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6  + 1(步数加一). 而对于有跳跃的点直接为dp[a]=dp[b]; #include<stdio.h>

hdu 4418 Time travel (概率dp 细节好多)

Time travel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1366    Accepted Submission(s): 303 Problem Description Agent K is one of the greatest agents in a secret organization called Men in

hdu3076ssworld VS DDD 概率dp

//ssworld VS DDD 两个人有血量值 hp1 , hp2 //两人掷骰子得到每一点的概率已知 //ssword赢的概率 //dp[i][j]  表示有第一个人血量为i,第二个人的血量为j第一个人赢的概率 //第一个人赢,第二个人赢 , 平局的概率为p1 , p2 , p3 //那么有dp[i][j] = p2*dp[i-1][j] + p1*dp[i][j-1] + p3*dp[i][j] //整理可得dp[i][j] = p2/(1-p3)*dp[i-1][j] + p1/(1-p

hdu3076--ssworld VS DDD(概率dp第三弹,求概率)

ssworld VS DDD Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1487    Accepted Submission(s): 304 Problem Description One day, sssworld and DDD play games together, but there are some special

HDU 4050 wolf5x(动态规划-概率DP)

wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402    Accepted Submission(s): 248 Special Judge Problem Description There are n grids in a row. The coordinates of grids are numbered fro