HDU 4089 Activation (Beijing Probability Problem in 11 years)

Source: Internet
Author: User

Question: activation sequence of xian5. There are four situations:

1. Registration failed, but the queue sequence is not affected. The probability is p1.

2. The connection fails. the first person in the team is at the end of the team. The probability is p2.

3. The registration is successful, and the team leaves the queue first. The probability is p3.

4. The server crashes and the activation stops. The probability is p4.

Locate the main character within K and calculate the probability of server crash.

Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 4089


It is easier to think of a two-dimensional DP

Dp [I] [j] indicates the total number of I persons in the queue. The probability that the event is expected when the main character is at the position j.

You can write the transfer equation.

Dp [I] [1] = dp [I] [1] * p1 + dp [I] [I] * p2 + p4 (You may fail to register yourself and continue for the second time, the connection may fail, and the server will crash)

Dp [I] [j] = dp [I] [j] * p1 + dp [I] [J-1] * p2 + dp [I-1] [J-1] * p3 + p4 (j <= k)

Dp [I] [j] = dp [I] [j] * p1 + dp [I] [J-1] * p2 + dp [I-1] [J-1] * p3 (j> k)


Put dp [I] [j] aside.

In addition, p21-p2/(1-p2) p31 = p3/(1-p1) p41 = p4/(1-p1 );

Dp [I] [1] = dp [I] [I] * p21-p41

Dp [I] [j] = dp [I] [J-1] * p21-dp [I-1] [J-1] * p31 + p41; (j <= k)

Dp [I] [j] = dp [I] [J-1] * p21-dp [I-1] [J-1] * p31; (j> k)

We can find that the latter part of dp [I-1] [J-1] can be solved in recursion, we make the latter part of c [j]

Then c [1] = p41 c [2] = dp [I-1] [J-1] * p31 + p41 ............

Dp [I] [j] can be introduced by dp [I] [J-1], but it can be found that there is a loop, dp [I] [1] is derived from dp [I] [I.

If the range is so large, it is certainly not necessary to use Gaussian deyuan.

We merge the formula and iterate it, so that we can first solve dp [I] [I], then we can get dp [I] [1], and the rest can be recursive.

Dp [I] [I] = dp [I] [I] * p21-^ I + c [2] ^ p21-^ (I-1 )...... C [I] + p41 * p21.

The question requires Dp [n] [m];


[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <cstring>
# Include <cmath>
# Define eps 1e-10
# Define N (1 <7) + 5
# Define inf 1 <20
# Define zero (a) (fabs (a) <eps)
# Define lson (step <1)
# Define rson (step <1 | 1)
Using namespace std;
Double p1, p2, p3, p4, p21-p31, p41;
Double dp [2005] [2005], c [2005];
Int n, m, k;
Int main (){
While (scanf ("% d % lf", & n, & m, & k, & p1, & p2, & p3, & p4 )! = EOF ){
If (zero (p4) {puts ("0.00000"); continue ;}
P21-p1 );
P31 = p3/(1-p1 );
P41 = p4/(1-p1 );
Dp [1] [1] = p4/(1-p1-p2 );
For (int I = 2; I <= n; I ++ ){
For (int j = 2; j <= (I <k? I: k); j ++)
C [j] = dp [I-1] [J-1] * p31 + p41;
For (int j = k + 1; j <= I; j ++)
C [j] = dp [I-1] [J-1] * p31;
Double p = 1, tmp = 0;
For (int j = I; j> 1; j --){
Tmp + = p * c [j];
P * = p21;
}
Dp [I] [I] = (tmp + p * p41)/(1-p * p21 );
Dp [I] [1] = p21-dp * dp [I] [I] + p41;
For (int j = 2; j <I; j ++)
Dp [I] [j] = p21-dp [I] [J-1] + c [j];
}
Printf ("%. 5f \ n", dp [n] [m]);
}
Return 0;
}

# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <cstring>
# Include <cmath>
# Define eps 1e-10
# Define N (1 <7) + 5
# Define inf 1 <20
# Define zero (a) (fabs (a) <eps)
# Define lson (step <1)
# Define rson (step <1 | 1)
Using namespace std;
Double p1, p2, p3, p4, p21-p31, p41;
Double dp [2005] [2005], c [2005];
Int n, m, k;
Int main (){
While (scanf ("% d % lf", & n, & m, & k, & p1, & p2, & p3, & p4 )! = EOF ){
If (zero (p4) {puts ("0.00000"); continue ;}
P21-p1 );
P31 = p3/(1-p1 );
P41 = p4/(1-p1 );
Dp [1] [1] = p4/(1-p1-p2 );
For (int I = 2; I <= n; I ++ ){
For (int j = 2; j <= (I <k? I: k); j ++)
C [j] = dp [I-1] [J-1] * p31 + p41;
For (int j = k + 1; j <= I; j ++)
C [j] = dp [I-1] [J-1] * p31;
Double p = 1, tmp = 0;
For (int j = I; j> 1; j --){
Tmp + = p * c [j];
P * = p21;
}
Dp [I] [I] = (tmp + p * p41)/(1-p * p21 );
Dp [I] [1] = p21-dp * dp [I] [I] + p41;
For (int j = 2; j <I; j ++)
Dp [I] [j] = p21-dp [I] [J-1] + c [j];
}
Printf ("%. 5f \ n", dp [n] [m]);
}
Return 0;
}


 

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.