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