Test instructions
R*c a square, starting from (a) in each square can be released magic (energy consumption 2) to know, after the release of Magic may be in situ, may reach the adjacent lattice or the right lattice, give the probability of the three
To reach the (r,c) lattice, consume the desired energy.
Analysis:
State OK, dp[i][j] means (i,j) to reach (R,C) also need energy value, then dp[r][c]=0,dp[1][1] is the answer
dp[i][j]=dp[i][j]*p[i][j][0]+dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0, re-move the item can be;
#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#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[1010][1010],p[1010][1010][4];intr,c;voidsolve () {memset (DP,0,sizeof(DP)); for(inti=r;i>=1;--i) for(intj=c;j>=1;--j) {if(I==R&&J==C)Continue; if(p[i][j][0]==1.000)Continue;//means there's no way to go, just stay where you aredp[i][j]=dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0; DP[I][J]/=(1.0-p[i][j][0]); } printf ("%.3lf\n", dp[1][1]);}intMain () { while(~SCANF ("%d%d",&r,&c)) { for(intI=1; i<=r;++i) for(intj=1; j<=c;++j) for(intk=0;k<3;++k) scanf ("%LF",&P[i][j][k]); Solve (); }return 0;}
HDU 3853-loop (Probabilistic DP Primer)