Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3076
An incredible question: in short, the smaller the blood volume, the higher the odds, so the two exchanged the blood volume during reading.
Obviously, the winning rate and negative rate of each round are fixed. Therefore, set PSC as the winning rate, pls as the negative rate, and peq as the flat rate,
The winning rate and negative rate in each game can be determined,
The odds and negatives in a stage with results are an infinite series.
PSC (new) = 1 * PSC + peq * PSC ....... = Lim (n-> positive infinity) (1-peq ^ N) * PSC/(1-peq) = PSC/(1-peq)
PLS (new) = 1 * PLS + peq * PLS ....... = Lim (n-> positive infinity) (1-peq ^ N) * pls/(1-peq) = pls/(1-peq)
Set P [I] [J] to the probability that HP of A is I, and HP of B is J
Obviously, the transfer formula is:
When I> 0, j> 0
P [I-1] [J] + = P [I] [J] * PLS (new)
P [I] [J-1] + = P [I] [J] * PSC (new)
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>using namespace std;const int maxn=2e3+3;double p[maxn];double pp[2][6];double psc,pls,peq;int a,b;double ans;void calc(){ psc=pls=peq=0; ans=0; memset(p,0,sizeof p); for(int i=0;i<6;i++){ for(int j=0;j<6;j++){ if(i==j)peq+=pp[0][i]*pp[1][j]; else if(i<j)pls+=pp[0][i]*pp[1][j]; else psc+=pp[0][i]*pp[1][j]; } } if(peq!=1){ psc/=(1-peq); pls/=(1-peq); } p[b]=1; for(int i=a;i>0;i--){ for(int j=b;j>0;j--){ p[j-1]+=p[j]*psc; } ans+=p[1]*psc; for(int j=b;j>0;j--){ p[j]*=pls; } }}int main(){ while(scanf("%d%d",&b,&a)==2){ for(int i=0;i<6;i++)scanf("%lf",pp[0]+i); for(int i=0;i<6;i++)scanf("%lf",pp[1]+i); calc(); printf("%.6f\n",ans); } return 0;}
HDU 3076 ssworld vs DDD probability DP, infinite series, OJ error question difficulty: 2