HDU 3076 ssworld VS DDD probability dp

Source: Internet
Author: User

Test instructions: A , b throw the dice, for each of the points of the big wins, flat for and, a first win m times a won, the second wins n times b win.

WA so many times this problem data is wrong, two people's blood is mistaken, the amount of the input of a is actually B, the input B is actually a, because of the interference of the draw phenomenon, so the first draw included in a win probability B win probabilities are calculated out, And then minus the probability of a draw (this place to pay special attention, because the DP record is won a few times so multiplied by the probability of the time only winning and losing can not be counted in the draw), and then in the case of a win has been removed, B wins the probability of calculation, so it can be calculated,

Assuming equation Dp[i][j] represents a win for J-th B wins the probability of I, then the state transfer is relatively simple:

DP[I][J] + = dp[i][j-1] * A_WIN;
DP[I][J] + = dp[i-1][j] * B_WIN;

Then it's important to note that B wins at most n-1 times, and a must just win m times,

At first did not pay attention, when a had already won the second state transfer already did not need to add again, one did not notice at the beginning, the second state transfer added once

And this problem, if the array open dp[2050][2050] will be mle .... Must be almost exactly 2005 * 2005



Problem Descriptionone Day, Sssworld and DDD play games together, but there is some special rules in the games.
They both has 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 would remain unchanged. If one of them becomes 0 HP, he loses.
As a result of technical differences between the and each of them has different probability of throwing 1, 2, 3, 4, 5, 6. So we couldn ' t predict who the final winner.


Inputthere is multiple test cases.
The first line is both integer HP1, HP2 (1 <= HP1, HP2 <=), said the first player Sssworld ' s HP And the second player DDD ' s HP.
The next lines each has six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets a point J. The input data ensures that the game is always have an end.

Outputone float with six digits through point, indicate the probability Sssworld won the game.
Sample Input
5 51.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 1.0005 50.000 0.000 0.000 0.000 0.000 1.0001.000 0.000 0.000 0.000 0.000 0.000

Sample Output
0.0000001.000000

Source2009 multi-university Training Contest 17-host by nudt 
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring>using namespace    Std;double dp[2000 + 5][2000 + 5];int main () {int n,m;    Double a[7],b[7];    Double A_win,b_win;        while (~SCANF ("%d%d", &n,&m)) {for (int i=0; i<6; i++) scanf ("%lf", &a[i]);        for (int i=0; i<6; i++) scanf ("%lf", &b[i]);        a_win=0;        b_win=0;        for (int i=1, i<6; i++) for (int j=0; j<i; j + +) A_win+=a[i]*b[j];        for (int i=1, i<6; i++) for (int j=0; j<i; j + +) B_win+=b[i]*a[j];        Double P=a_win+b_win;        A_win/=p;        B_win/=p;        Memset (Dp,0,sizeof (DP));        Dp[0][0]=1;                    for (int j=0; j<n; j + +) for (int i=0; i<m; i++) {if (i+j>0) {                    if (i>0) Dp[i][j]+=dp[i-1][j]*b_win;                 if (j>0)       Dp[i][j]+=dp[i][j-1]*a_win;        }} double ans=0; for (int i=0; i<m; i++)//This place because there are two conditions caused by the first is when a won n times then stopped, if the above is <=n then there will be a repetition, so use n-1 and then multiply the probability of winning again ans+=dp[i][n-        1]*a_win;        if (ans>1) Ans=1;    printf ("%.6lf\n", ans); } return 0;}


HDU 3076 ssworld VS DDD probability dp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.