Main topic
There is a man trapped in a r*c (2<=r,c<=1000) Maze, at first he at this point, the exit of the Maze is (R,C). In each lattice of the maze, he can spend 2 mana to turn on the transmission channel. Assuming that he (X, y) in this lattice, after opening the transmission channel, there is p_lift[i][j] probability of being sent to (x,y+1), there is p_down[i][j] probability of being sent to (X+1,y), there is p_loop[i][j] probability is sent to (x, y). Ask him what the expected value of the mana to be spent on the exit.
It's much better to ask for a simple expectation, to understand the difference between expectation and probability.
Problem Descriptionakemi Homura is a Mahou shoujo (Puella magi/magical Girl).
Homura wants to help his friend Madoka save the world. But because of the plot of the Boss incubator, she's trapped in a labyrinth called LOOPS.
The planform of the LOOPS is a rectangle of r*c grids. There is a portal with each grid except the exit grid. It costs Homura 2 magic power to use a portal once. The portal in a grid g (r, c) would send Homura to the grid below G (Grid (r+1, C)), and the grid on the right of G (Grid (R, c+1) ), or even G itself at respective probability (what evil the Boss incubator is)!
At the beginning Homura are in the top left corner of the LOOPS ((1, 1)), and the exit of the labyrinth are in the bottom RI Ght Corner ((R, C)). Given the probability of transmissions of each portal, your task was help poor Homura calculate the EXPECT magic power She Need to escape from the LOOPS.
Inputthe first line contains, integers r and C (2 <= R, c <= 1000).
The following R lines, each contains c*3 real numbers, at 2 decimal places. Every three numbers make a group. The first, second and third number of the CTH group of line R represent the probability of transportation to Grid (R, c), Grid (R, c+1), Grid (R+1, c) of the portal in grid (R, c) respectively. Groups of numbers is separated by 4 spaces.
It is ensured the sum of three numbers in each group is 1, and the second numbers of the rightmost groups is 0 (as T Here is no grids on the right of them) while the third numbers of the Downmost groups is 0 (as there are no grids below them).
Ignore the last three numbers of the input data. They is printed just for looking neat.
The answer is ensured no greater than 1000000.
Terminal at EOF
Outputa real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOO Ps.
Sample Input
2 20.00 0.50 0.50 0.50 0.00 0.500.50 0.50 0.00 1.00 0.00 0.00
Sample Output
6.000
Source2011 Invitational Contest Host by Bupt
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring>using namespace Std;struct node{ Double x, Y, Z,} f[1012][1012];d ouble dp[1012][1012];int Main () { int n,m; while (~SCANF ("%d-%d", &n,&m)) {for (int. i=0; i<n; i++) for (int j=0; j<m; j + +) scanf ("%lf %lf%lf ", &f[i][j].x,&f[i][j].y,&f[i][j].z); 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 (f[i][j].x!=1) { dp[i][j]=dp[i][j+1]*f[i][j].y+dp[i+1][j]*f[i][j].z+1; Dp[i][j]/= (1-f[i][j].x); }}} printf ("%.3lf\n", dp[0][0]*2); } return 0;}
HDU 3853 LOOPS probability dp