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 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

求概率,和求期望的方法相同,不过不用再+1,dp[i][j]表示a有i血量,b有j血量时a赢的概率,因为要求a赢的概率,所以在dp[i][0]a赢得概率是1,dp[0][j]时a赢的概率是0。

一个坑点,血量是倒着输入的。。。。坑了一天。。。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int hp1 , hp2 ;
double dp[2][2100] ;
double a , b , p ;
double ka[10] , kb[10] ;
int main()
{
    int i , j , flag ;
    while(scanf("%d %d", &hp2, &hp1)!=EOF)
    {
        for(i = 1 ; i <= 6 ; i++)
            scanf("%lf", &ka[i]);
        for(j = 1 ; j <= 6 ; j++)
            scanf("%lf", &kb[j]);
        memset(dp,0,sizeof(dp));
        a = b = p = 0.0 ;
        for(i = 1 ; i <= 6 ; i++)
            for(j = 1 ; j <= 6 ; j++)
            {
                if(i > j)
                    a += ka[i]*kb[j] ;
                else if( i < j )
                    b += ka[i]*kb[j] ;
                else
                    p += ka[i]*kb[j] ;
            }
        dp[0][0] = dp[1][0] = 1.0 ;
        flag = 0 ;
        for(i = 1 ; i <= hp1 ; i++)
        {
            flag = 1 - flag ;
            for(j = 0 ; j <= hp2 ; j++)
            {
                if( j == 0 ) continue ;
                dp[flag][j] = ( a*dp[flag][j-1] + b*dp[1-flag][j] ) / (1.0-p) ;
            }
        }
        printf("%.6lf\n", dp[flag][hp2]);
    }
    return 0;
}

时间: 2024-08-06 15:36:47

hdu3076--ssworld VS DDD(概率dp第三弹,求概率)的相关文章

zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)

One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces. All the

poj3744--Scout YYF I(概率dp第五弹:矩阵优化)

Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5093   Accepted: 1385 Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties,

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

HDU3076 ssworld VS DDD

嘟嘟嘟 友情提示:数据把\(hp1\)和\(hp2\)弄反了! 进入正题. 这题还是比较好想,令\(dp[i][j]\)表示第一个人赢了\(i\)场,第二个人赢了\(j\)的概率,转移就是分别考虑这一场谁赢了. 所以我们要预处理两个人赢的概率.显然有\(winA = \sum _ {i = 1} ^ 6 \sum _ {j = 1} ^ {i - 1} p1[i] * p2[j]\),\(winB = \sum _ {i = 1} ^ 6 \sum _ {j = i + 1} ^ {n} p1[

hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1628    Accepted Submission(s): 1103 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids la

HDU 4405:Aeroplane chess(概率DP入门)

http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six f

概率dp入门

概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> typedef long long ll; using namespace std

HDU - 1099 - Lottery - 概率dp

http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[n]=0,因为我们已经集齐了. \[dp[i]=(\frac{i}{n}*dp[i]+\frac{n-i}{n}*dp[i+1])+1\] 移项得答案. 然后写个分数类,注意约分. #include<bits/stdc++.h> using namespace std; typedef long

HDU 3076:ssworld VS DDD(概率DP)

http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD 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 g