Hdu 3853 LOOPS (expectation for probabilistic dp reverse push)

Source: Internet
Author: User

Question link

LOOPS

Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission (s): 2630 Accepted Submission (s): 1081


Problem DescriptionAkemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl ).

Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth called LOOPS.

The planform of the LOOPS is a rectangle of R * C grids. there is a portal in each grid does T the exit grid. it costs Homura 2 magic power to use a portal once. the portal in a grid G (r, c) will send Homura to the grid below G (grid (r + 1, c )), the grid on the right of G (grid (r, c + 1), or even G itself at respective probability (How edevil the Boss Incubator is )!
At the beginning Homura is in the top left corner of the LOOPS (1, 1), and the exit of the labyrinth is in the bottom right corner (R, C )). given the probability of transmissions of each portal, your task is help poor Homura calculate the specific Ct magic power she need to escape from the LOOPS.




 

 

InputThe first line contains two 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. two groups of numbers are separated by 4 spaces.

It is ensured that the sum of three numbers in each group is 1, and the second numbers of the rightmost groups are 0 (as there are no grids on the right of them) while the third numbers of the downmost groups are 0 (as there are no grids below them ).

You may ignore the last three numbers of the input data. They are 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 specific Ct magic power Homura need to escape from the LOOPS.

 

 

Sample Input2 20.00 0.50 0.50 0.50 0.00 0.500.50 0.50 0.00 1.00 0.00

 

Sample Output6.000:

There is a m column in the r row of the maze. The start point is []. Now we want to go to [r, c].
For [x, y] at a point, you can open a door to [x + 1, y] or [x, y + 1].
Consumes 2 magic points
Ask how much magic power is consumed on average [r, c]

Analysis:

Similar to the previous question, reverse push

D [I] [j] indicates the expectation from column j of row I to column c of row r, d [I] [j] = 1 + d [I] [j] * p1 + d [I] [j + 1] * p2 + d [I + 1] [j] * p3.

The shift is

D [I] [j] = (1.0 + d [I] [j + 1] * p [I] [j]. B + d [I + 1] [j] * p [I] [j]. c)/(1.0-p [I] [j]. a );

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cstdlib> 5 # include <queue> 6 # include <cmath> 7 # include <algorithm> 8 # define LL _ int64 9 const int maxn = 1e3 + 10; 10 using namespace std; 11 double d [maxn] [maxn]; 12 struct node13 {14 double a, B, c; 15} p [maxn] [maxn]; 16 17 int main () 18 {19 int r, c, I, j; 20 while (~ Scanf ("% d", & r, & c) 21 {22 for (I = 1; I <= r; I ++) 23 for (j = 1; j <= c; j ++) 24 scanf ("% lf", & p [I] [j]. a, & p [I] [j]. b, & p [I] [j]. c); 25 26 memset (d, 0, sizeof (d); 27 d [r] [c] = 0; 28 for (I = r; I> = 1; I --) 29 for (j = c; j> = 1; j --) 30 if (I = r & j = c) 31 continue; 32 else if (p [I] [j]. a-1.0 = 0) // This is because the error is twice. If this point is only in the same place, the reverse push is not reachable, that is, d [I] [j] = 0.33 continue; 34 else35 d [I] [j] = (1.0 + d [I] [j + 1] * p [I] [j]. B + d [I + 1] [j] * p [I] [j]. c)/(1.0-p [I] [j]. a); 36 printf ("%. 3lf \ n ", 2.0 * d [1] [1]); 37} 38 return 0; 39}

 

 

Hdu 3853 LOOPS (expectation for probabilistic dp reverse push)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.