Hdu3076ssworld VS DDD probability dp

Source: Internet
Author: User

Ssworld VS DDD Two humans have a blood value of HP1, HP2
Two people throw the dice to get the probability of each point known
The probability of ssWOrd win
DP[I][J] Indicates the first person has a blood volume of I, the second person's blood volume is J the probability of the first person to win
The first person wins, the second person wins, the probability of a draw is P1, p2, p3
Then have dp[i][j] = P2*dp[i-1][j] + p1*dp[i][j-1] + p3*dp[i][j]
Finishing can get dp[i][j] = p2/(1-P3) *dp[i-1][j] + p1/(1-P3) *dp[i][j-1]
The special pit is the amount of blood that is poured backwards.
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace Std;
const int MAXN = 2010;
Double DP[2][MAXN];
Double p[2][6];
int main ()
{
Freopen ("In.txt", "R", stdin);
Freopen ("OUT.txt", "w", stdout);
int n, m;
while (~SCANF ("%d%d", &m, &n))
{
Double p3 = 0, p1 = 0, p2 = 0;
for (int i = 0;i < 2;i++)
for (int j = 0; J < 6; J + +)
scanf ("%lf", &p[i][j]);
for (int i = 0;i < 6;i++)
{
for (int j = 0;j < I; j + +)
p1+= P[0][i]*p[1][j];
for (int j = i+1; J < 6;j++)
P2 + = P[0][i]*p[1][j];
}
P3 = 1-P1-P2;
if (P3 = = 1) {puts ("0"); continue;}
memset (DP, 0, sizeof (DP));
Dp[0][0] = dp[1][0] = 1;
for (int i = 1;i <= n; i++)
for (int j = 1;j <= m;j++)
DP[I%2][J] = p2/(1-P3) *dp[(i-1)%2][j] + p1/(1-P3) *dp[i%2][j-1];
printf ("%.6lf\n", Dp[n%2][m]);
}
return 0;
}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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