LOOPS
Time limit:15000/5000 MS (java/others) Memory limit:125536/65536 K (java/others)
Total submission (s): 3738 Accepted Submission (s): 1488
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 INPUT2 20.00 0.50 0.50 0.50 0.00 0.500.50 0.50 0.00 1.00 0.00 0.00
Sample Output6.000
Source2011 Invitational Contest Host by bupt test instructions: In the diagram of N*m, for each point, give you the probability of moving down or to the right, asking you from 0, 0 to n,m the desired question: dp[i][j] means from (i,j) to (N,M) The desired size
dp[i][j]=p2[i][j]*dp[i][j+1]/(1-p1[i][j]) +p3[i][j]*dp[i+1][j]/(1-p1[i][j]) +2/(1-p1[i][j]);
///1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#definePush_back PB#defineMem (a) memset (A,0,sizeof (a))#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (A, b) scanf ("%d%d", &a,&b)#defineMoD 1000000007#defineINF 100000#defineMAXN 1001inline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//******************************************************************intn,m;DoubleP1[MAXN][MAXN],P2[MAXN][MAXN],P3[MAXN][MAXN];DoubleDP[MAXN][MAXN];intMain () { while(READ (n,m)! =EOF) {for (I,0, N-1) for (J,0, M-1) scanf ("%LF%LF%LF",&p1[i][j],&p2[i][j],&P3[i][j]); MEM (DP); Forj (I,n-1,0) Forj (j,m-1,0) { if(i==n-1&&j==m-1){Continue;} if(p1[i][j]==1) dp[i][j]=0; ElseDp[i][j]=p2[i][j]*dp[i][j+1]/(1-P1[I][J]) +p3[i][j]*dp[i+1][j]/(1-P1[I][J]) +2/(1-P1[i][j]); } printf ("%.3f\n", dp[0][0]); } return 0;}
Code
HDU 3853 probability DP