Test instructions: The initial state at (the primary) position, the goal is to go (n,n), each can only downward to the right or not to move, known in each lattice when the probability of these three cases, each move one step consumes 2 of the magic, to go to the end of the use of the magic of the expectation.
Analysis: Simple expected DP, to apply the previous frame, but this question is not +1, but +2, because each time the number of extra is to take a step of consumption , here is 2! Note P1[i][j]==1 can not calculate dp[i][j], see the equation will know, the denominator can not be 0.
Code:
#include <iostream> #include <cstdio>using namespace Std;int n,m;double p1[1005][1005],p2[1005][1005],p3[ 1005][1005],dp[1005][1005];int Main () {while (scanf ("%d%d", &n,&m)!=eof) {for (Int. i=0;i<n;i++) for (int j=0; j<m;j++) scanf ("%lf%lf%lf", &p1[i][j],&p2[i][j],&p3[i][j]); Memset (Dp,0,sizeof (DP)); for (int i=n-1;i >=0;i--) {for (int j=m-1;j>=0;j--) {if (i==n-1&&j==m-1) continue;if (p1[i][j]==1.0) continue; dp[i][j]=p2 I [J]*dp[i][j+1]+p3[i][j]*dp[i+1][j]+2.0;dp[i][j]/= (1.0-p1[i][j]);}} printf ("%.3lf\n", Dp[0][0]);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 3853 down to the right for an exit question-expected DP