Title: A new game registered account, there are N users in line. The following four scenarios may occur with each user's information being processed:
1. Processing failure, re-processing, processing information is still in the team head, the probability of occurrence is P1;
2. Handling errors, processing information to the end of the queue again, the probability of occurrence is P2;
3. Processing success, team head information processing success, out of the team, the probability of occurrence is P3;
4. Server failure, all information in the team is lost, the probability of occurrence is P4;
Xiao Ming is now in the ranks of the M position, asked when he was in front of the number of messages does not exceed the probability of server failure k-1.
Problem Analysis: The state transfer equation of this problem is not difficult to write. The definition state DP (I,J) indicates the probability of reaching the required state when he is in the first position in the group with the I person. The state transition equation is:
DP (i,1) =P1*DP (i,1) +P2*DP (i,i) +P4
DP (I,J) =P1*DP (i,j) +p2* (i,j-1) +P3*DP (i-1,j-1) +p4 (2<=j<=k)
DP (I,J) =P1*DP (i,j) +p2* (i,j-1) +P3*DP (i-1,j-1) (k<j<=i)
Tidy up, and another p21=p2/(1-P1), p31=p3/(1-P1), p41=p4/(1-P1), then get:
DP (i,1) =P21*DP (i,i) +p41
DP (I,J) =P21*DP (i,j-1) +P31*DP (i-1,j-1) +p41 (2<=j<=k)
DP (I,J) =P21*DP (i,j-1) +P31*DP (i-1,j-1) (k<j<=i)
This can be solved by recursion.
For ease of writing, the above three transfer equations are expressed in two equations:
DP (i,1) =P21*DP (i,i) +c (1)
DP (I,J) =P21*DP (i,j-1) +c (j) (2<=j<=i)
DP (I,I) can be obtained by iterating:
(1-p21^i) DP (i,i) =∑ (p21^ (i-j)) *c (j) (1<=j<=i)
PS: Have to add special sentence, otherwise will wa!! ...
The code is as follows:
# include<iostream># include<cstdio># include<cmath># include<cstring># include< Algorithm>using namespace Std;const double eps=1e-5;int n,m,k;double p1,p2,p3,p4;double dp[2005][2005];int Main () {W Hile (~scanf ("%d%d%d", &n,&m,&k)) {scanf ("%lf%lf%lf%lf", &P1,&P2,&P3,&P4); if (p4<eps) {printf ("0.00000\n"); Continue } double p21=p2/(1-P1); Double p31=p3/(1-P1); Double p41=p4/(1-P1); dp[1][1]=p41/(1-P21); for (int i=2;i<=n;++i) {dp[i][i]=0; for (int j=1;j<=i;++j) {if (j==1) Dp[i][i]+=pow (p21,i-j) *p41; else if (j>=2&&j<=k) Dp[i][i]+=pow (p21,i-j) * (P31* (dp[i-1][j-1]) +p41); else Dp[i][i]+=pow (p21,i-j) *p31*dp[i-1][j-1]; } dp[i][i]/= (1-pow (p21,i)); for (int j=1;j<i;++j) {if (j==1) dp[i][j]=p21*dp[i][i]+p41; Else if (j>=2&&j<=k) dp[i][j]=p21*dp[i][j-1]+p31*dp[i-1][j-1]+p41; else dp[i][j]=p21*dp[i][j-1]+p31*dp[i-1][j-1]; }} printf ("%.5lf\n", Dp[n][m]); } return 0;}
HDU-4089 Activation (probability dp seeking probability)