Test instructions
Walk n step, give each step to the left to go the probability of L, the right to go to the probability of R, left in situ probability 1-l-r, to achieve the farthest right distance expectation.
Analysis
Start in the way of the desire to reverse the analysis, but let is the right edge can not retreat, Meng a will, since the inverse cannot beg, first is to seek probability, and then according to the definition of expectations, try it, think of State, Dp[i][j][k], said I step the current position is J the farthest right boundary is k when the probability, Because the position can be negative, the position is added N.
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineN 110#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[n][2*N] [N],l,r;intMain () {intn,o,t; scanf ("%d",&t); while(t--) {scanf ("%D%D%LF%LF",&o,&n,&l,&R); Memset (DP,0,sizeof(DP)); dp[0][n][n]=1; for(intI=0; i<n;++i) { for(intj=0; j<=2*n;++j) for(intk=j;k<=2*n;++k) {dp[i+1][j][k]+=dp[i][j][k]* (1-LR); Dp[i+1][j-1][k]+=dp[i][j][k]*M; if(j+1>k) Dp[i+1][j+1][k+1]+=dp[i][j][k]*R; ElseDp[i+1][j+1][k]+=dp[i][j][k]*R; } } //definition of expectations DoubleTotal=0.0; for(intj=0; j<=2*n;++j) for(intk=j;k<=2*n;++k) Total+=dp[n][j][k]* (K-N); printf ("%d%.4lf\n", O,total); }return 0;}
Maximum Random Walk (probability dp)