"Hdoj" "4089" Activation

Source: Internet
Author: User

Probability DP

The 5th question in Kuangbin summary

Copy:

HDU 4098 Test Instructions: There are n people waiting in line to activate the game on the official website. Tomato is ranked in the first M. For the first person in a queue. There is a situation: 1, the activation failed, left in the queue to wait for the next activation (probability of P1) 2, lost connection, out of the queue, and then ranked at the end of the queue (probability is P2) 3, the activation succeeds, leaving the queue (probability is P3) 4, the server is down, the server stops activating, everyone cannot activate The probability of tomato the position of the <=k in the queue when the server is paralyzed: probability dp; set dp[i][j] means I person queue, tomato row in the first J position, the probability of reaching the target State (j<=i) dp[n][m] is the desired j==1:dp[i][1  ]=p1*dp[i][1]+p2*dp[i][i]+p4;2<=j<=k:dp[i][j]=p1*dp[i][j]+p2*dp[i][j-1]+p3*dp[i-1][j-1]+p4;k<j<=i: DP[I][J]=P1*DP[I][J]+P2*DP[I][J-1]+P3*DP[I-1][J-1]; Simplification: J==1:DP[I][1]=P*DP[I][I]+P41;2&LT;=J&LT;=K:DP[I][J]=P*DP I [j-1]+p31*dp[i-1][j-1]+p41;k<j<=i:dp[i][j]=p*dp[i][j-1]+p31*dp[i-1][j-1];: p=p2/(1-P1);p 31=p3/(1-P1) p41 =p4/(1-P1) can be cyclic i=1->n recursive solution dp[i]. Dp[i] is equivalent to a constant when solving dp[i-1]. When solving dp[i][1~i] wait for the following I equation J==1:dp[i][1]=p*dp[i][i]+c[1];2<=j<=k:dp[i][j]=p*dp[i][j-1]+c[j];k<j=i:dp[i][j] =P*DP[I][J]+C[J], where c[j] are constant. The above equation can be solved dp[i]. The first is the iteration to get dp[i][i]. Then you can get all the dp[i in the next generation]. Pay attention to a case of special judgment. Is P4<eps time, will not collapse, should direct output 0*/

Ah ... The iteration didn't understand at first ... Then I wrote it myself:

F (i,1) =f (i,i) *p+c[1]

F (i,2) =f (i,1) *p+c[2]

......

F (i,i) =f (i,i-1) *p+c[i]

By substituting the former i-1 in the first I formula, you can get:

F (i,i) = ... [(f (i,i) *p+c[1]) *p + c[2]]*p +c[3] ...

(f (i,i) *p plus c[1], then *p,+c[2], then *p,+c[3] ... (Qin Jiushao algorithm?) )

Fully expanded to get:

F (i,i) =f (i,i) *p^i+c[1]*p^ (i-1) + ...

You can figure out F (i,i) ...

1 //hdoj 40892#include <cmath>3#include <vector>4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <iostream>8#include <algorithm>9 #defineRep (i,n) for (int i=0;i<n;++i)Ten #defineF (i,j,n) for (int i=j;i<=n;++i) One #defineD (i,j,n) for (int i=j;i>=n;--i) A #definePB Push_back - using namespacestd; - intGetint () { the     intv=0, sign=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; + } - Const intn= ., inf=~0u>>2; + Const Doubleeps=1e-6; A /*******************template********************/ at  - DoubleF[n][n],pp[n],c[n]; - intMain () { - //freopen ("Input.txt", "R", stdin); -     intn,m,k; -     DoubleP1,P2,P3,P4; in      while(SCANF ("%D%D%D%LF%LF%LF%LF", &AMP;N,&AMP;M,&AMP;K,&AMP;P1,&AMP;P2,&AMP;P3,&AMP;P4)! =EOF) { -         if(p4<EPS) { toprintf"0.00000\n"); +             Continue; -         } the         Doublep=p2/(1-p1), *p41=p4/(1-p1), $P31=P3/(1-p1);Panax Notoginsengpp[0]=1.0; -F (I,1, N) pp[i]=p*pp[i-1]; the          +f[1][1]=P41/(1-p); Ac[1]=p41; theF (I,2, N) { +F (J,2, k) c[j]=p31*f[i-1][j-1]+p41; -F (j,k+1, i) c[j]=p31*f[i-1][j-1]; $             Doubletmp=c[1]*pp[i-1]; $F (J,2, i) tmp+=c[j]*pp[i-j]; -f[i][i]=tmp/(1-pp[i]); -f[i][1]=p*f[i][i]+c[1]; theF (J,2, I-1) f[i][j]=p*f[i][j-1]+C[j]; -         }Wuyiprintf"%.5lf\n", F[n][m]); the     } -     return 0; Wu}
View Code

"Hdoj" "4089" Activation

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.