Hdu4089activation probability DP

Source: Internet
Author: User

A queue for the first person's situation
Probability P1: The queue remains the same
P2: First person to the end of the team
P3: First person out of the team
P4: System crashes
There are n people in the queue, Tomato in the M position, the system crashes, the number of people in front of the Tomato is less than the probability of the case of the K person
DP[I][J] Indicates the probability that there is an I person in the queue, and that the target State occurs when the Tomato is in position J
You can easily get a recursive formula
DP[I][1] = p2/(1-P1) *dp[i][i] + p4/(1-P1);
DP[I][J] = p2/(1-P1) *dp[i][j-1] + p3/(1-P1) *dp[i-1][j-1] + p4/(1-P1);
DP[I][J] = p2/(1-P1) *dp[i][j-1] + p3/(1-P1) *dp[i-1][j-1];
Only three cases occurred on tomato, successfully out of the team, the system crashes more than K when the system crashes is less than or equal to K
So the initial conditions dp[1][1] = p4/(P3+P4)
And then each time we iterate through the dp[i][i], get the answer.
It is important to note that two-dimensional arrays are hyperspace, so use a scrolling array
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace Std;
const int MAXN = 2010;
Double DP[2][MAXN];
int n, m, K;
int main ()
{
Freopen ("In.txt", "R", stdin);
Double P1, p2, p3, P4, TMP, temp;
int I, J;
while (~SCANF ("%d%d%d%lf%lf%lf%lf", &n, &m, &k, &p1, &AMP;P2, &AMP;P3, &AMP;P4))
{
memset (DP, 0, sizeof (DP));
if (P4 = = 0)
{
Puts ("0.00000");
Continue;
}
DP[1][1] = p4/(P3+P4);
for (i = 2;i <= n;i++)
{
TMP = 0;
temp = 1;
for (j = i;j > 0; j--)
{
if (j = = 1) tmp+= p4/(1-P1) *temp;
else if (J > K) tmp+=p3/(1-P1) *dp[(i-1)%2][j-1]*temp;
Else tmp+= (p3/(1-P1) *dp[(i-1)%2][j-1] + p4/(1-P1)) *temp;
temp*=p2/(1-P1);
}
Dp[i%2][i] = tmp/(1-temp);
for (j = 1;j < I; j + +)
{
if (j = = 1) dp[i%2][1] = p2/(1-P1) *dp[i%2][i] + p4/(1-P1);
else if (J <= k) dp[i%2][j] = p2/(1-P1) *dp[i%2][j-1] + p3/(1-P1) *dp[(i-1)%2][j-1] + p4/(1-P1);
else dp[i%2][j] = p2/(1-P1) *dp[i%2][j-1] + p3/(1-P1) *dp[(i-1)%2][j-1];
}
}
printf ("%.5lf\n", Dp[n%2][m]);
}
}

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

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