Poj 3308 (minimum cut + logarithm processing)

Source: Internet
Author: User

This is a very difficult topic,The word "product" means "multiplication" in this question.

Then, the creation of the minimal cut model, S = 0, T = m + n + 1, and then from S to 1-m, the permission is set to CI.An edge that is created from m + 1-m + n to the edge with the t weight Ri. Then, the coordinates (x, y) of each paratroopers establish an edge with an X-> Y weight of infinity.

The key point of this question is to find the minimum product of all expenses. What we can know is that the sum of all expenses is obtained using the minimal cut model. If we want to process multiplication operations, it seems difficult to do so, however, there is a clever method:

Take the right value of each edge first to the logarithm (log is based on E, log10 is based on 10), and then the operations in the network stream are both +-, and the logarithm is equivalent to multiplication and division, we can see that if the weights and the maximum values after the logarithm are obtained, then exp (the square of E) will obtain the maximum total product.

When multiplication is difficult to process in the future, think about whether the operation that converts logarithm to +-can solve it.

 

Paratroopers
Time limit:1000 ms   Memory limit:65536 K
Total submissions:5432   Accepted:1617

Description

It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the Mars. recently, the commanders of the earth are informed by their spies that the invaders of Mars want to land some paratroopers in the m × n Grid yard of one their main weapon factories in order to destroy it. in addition, the spies informed them the row and column of the places in the yard in which each paratrooper will land. since the paratroopers are very strong and well-organized, even one of them, if your ved, can complete the mission and destroy the whole factory. as a result, the Defense Force of the Earth must kill all of them simultaneously after their landing.

In order to accomplish this task, the Defense Force wants to utilize some of their most hi-tech laser guns. they can install a gun on a row (resp. column) and by firing this gun all paratroopers landed in this row (resp. column) will die. the cost of installing a gun inITh row (resp. Column) of the grid yard isRi(Resp.Ci) And the total cost of constructing a system firing all guns simultaneously is equal to the product of their costs. now, your team as a high rank defense group must select the guns that can kill all paratroopers and yield minimum total cost of constructing the firing system.

Input

Input begins with a numberTShowing the number of test cases and then,TTest Cases Follow. Each test case begins with a line containing three integers 1 ≤M≤ 50, 1 ≤N≤ 50 and 1 ≤L≤ 500 showing the number of rows and columns of the yard and the number of paratroopers respectively. After that, a lineMPositive real numbers greater or equal to 1.0 comes whereITh number isRiAnd then, a lineNPositive real numbers greater or equal to 1.0 comes whereITh number isCi. Finally,LLines Come each containing the row and column of A paratro.

Output

For each test case, your program must output the minimum total cost of constructing the firing system rounded to four digits after the fraction point.

Sample Input

 
14 4 52.0 7.0 5.0 2.01.5 2.0 2.0 8.01 12 23 34 41 4

Sample output

 
16.0000

Source

Amirkabir University of Technology local contest 2006

 

 1 # Include <stdio. h> 2 # Include < String . H> 3 # Include <math. h> 4 # Include <String > 5 # Include <iostream> 6   Using   Namespace  STD;  7   # Define N 110 8   # Define M 5 * n 9   # Define INF 0x3ffffff 10   11   Struct Node  12   {  13       Int  To, next;  14       Double  W;  15   } Edge [m];  16   17   Int  CNT, pre [N];  18   Int S, T;  19   Int  Nn;  20   Int  N, m;  21   Int  LV [N], gap [N];  22   23   Void Add_edge ( Int U, Int V, Double W)  24   {  25 Edge [CNT]. To = V;  26 Edge [CNT]. W = W;  27 Edge [CNT]. Next = Pre [u];  28 Pre [u] = CNT ++ ;  29   }  30   31   Double Sdfs ( Int K, Double  W)  32   {  33       If (K = T) Return  W;  34       Double F = 0  ;  35       Int Mi = nn- 1 ;  36       For ( Int P = pre [k]; P! =- 1 ; P = Edge [p]. Next)  37   {  38           Int V = Edge [p].;  39           If (Edge [p]. W! = 0  )  40  {  41               If (LV [k] = lv [v] + 1  )  42   {  43                   Double TMP = sdfs (v, min (w- F, edge [p]. W ));  44 F + = TMP;  45 Edge [p]. W-= TMP;  46 Edge [P ^ 1 ]. W + = TMP;  47                   If (F = w | LV [s] = nn) Return  F;  48   }  49               If (LV [v] <mi) MI = LV [v];  50   }  51   } 52       If (F = 0  )  53   {  54 Gap [LV [k] -- ;  55           If (Gap [LV [k] = 0  )  56   {  57 LV [s] = Nn; 58               Return  F;  59   }  60 LV [k] = MI + 1  ;  61 Gap [LV [k] ++ ;  62   }  63       Return  F;  64   } 65   66   Double  SAP ()  67   {  68 Nn = T + 1  ;  69       Double Sum = 0  ;  70 Memset (LV, 0 , Sizeof (LV ));  71 Memset (gap, 0 , Sizeof  (GAP ));  72 Gap [ 0 ] = Nn;  73       While (LV [s] < Nn)  74   {  75 Sum + = Sdfs (S, INF ); 76   }  77       Return  SUM;  78   }  79   Int  Main ()  80   {  81       Int  T1, P;  82 Scanf ( " % D  " ,& T1 );  83       While (T1 -- )  84   {  85 CNT = 0  ;  86 Memset (PRE ,- 1 , Sizeof  (Pre ));  87 Scanf ( "  % D  " , & N, & M ,& P );  88 S = 0  ;  89 T = n + M + 1  ;  90           For ( Int I = 1 ; I <= N; I ++ ) 91   {  92               Double  W;  93 Scanf ( "  % Lf  " ,& W );  94   Add_edge (S, I, log (w ));  95 Add_edge (I, S, 0  );  96  }  97           For ( Int I = 1 ; I <= m; I ++ )  98   {  99               Double  W;  100 Scanf ( "  % Lf  " ,& W ); 101 Add_edge (n + I, T, log (w ));  102 Add_edge (t, n + I, 0  );  103   }  104           For ( Int I = 0 ; I <p; I ++ )  105   {  106              Int  X, Y;  107 Scanf ( "  % D  " , & X ,& Y );  108 Add_edge (x, N + Y, INF );  109 Add_edge (n + Y, X, 0  );  110   }  111 Printf ("  %. 4lf \ n  "  , Exp (SAP ()));  112   }  113       Return   0  ;  114 }

 

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.