Poj_3308
This topic is a bit similar to the minimum point set coverage problem in a bipartite graph. However, due to the edge weight, the maximum matching of a bipartite graph cannot be used directly.
After referring to the ideas of others, I found that the Binary Graph is still used in the diagram, and the rows and columns are considered as a set. Because the minimum value of the product of cost is obtained, so first passLog2Billing method. The capacity between the source point and the row is initializedLog2Row fee, capacity initialization between columns and settlement pointsLog2Column fees. Then, a directed edge is connected between the row and column corresponding to the positions of the paratroopers. The capacity isINF.
At last, we only need to perform a minimum cut, that is, the maximum network flow.
# Include < Stdio. h >
# Include < String . H >
# Include < Math. h >
Double Cap [ 110 ] [ 110 ], Flow [ 110 ] [ 110 ], [ 110 ];
Int Q [ 110 ], P [ 110 ];
Int Main ()
{
Int I, j, k, n, M, L, T, T, U, V, front, rear;
Double F, temp;
Scanf ( " % D " , & T );
While (T -- )
{
Scanf ( " % D " , & M, & N, & L );
T = M + N + 1 ;
For (I = 0 ; I <= T; I ++ )
For (J = 0 ; J <= T; j ++ )
{
Cap [I] [J] = 0.0 ;
Flow [I] [J] = 0.0 ;
}
For (I = 1 ; I <= M; I ++ )
{
Scanf ( " % Lf " , & Temp );
Cap [ 0 ] [I] = Log2 (temp );
}
For (I = M + 1 ; I < T; I ++ )
{
Scanf ( " % Lf " , & Temp );
Cap [I] [T] = Log2 (temp );
}
For (I = 0 ; I < L; I ++ )
{
Scanf ( " % D " , & U, & V );
Cap [u] [m + V] = 1000000000.0 ;
}
F = 0 ;
While ( 1 )
{
For (I = 1 ; I <= T; I ++ )
A [I] = 0.0 ;
A [ 0 ] = 1000000000.0 ;
Front = Rear = 0 ;
Q [rear ++ ] = 0 ;
While (Front < Rear)
{
U = Q [Front ++ ];
For (V = 0 ; V <= T; V ++ )
If (A [v] < 1e - 8 && Cap [u] [v] > Flow [u] [v])
{
Temp = Cap [u] [v] - Flow [u] [v];
A [v] = A [u] < Temp ? A [u]: temp;
P [v] = U;
Q [rear ++ ] = V;
}
}
If (A [T] < 1e - 8 )
Break ;
For (U = T; u ! = 0 ; U = P [u])
{
Flow [p [u] [u] + = A [T];
Flow [u] [p [u] -= A [T];
}
F + = A [T];
}
Printf ( " %. 4f \ n " , POW ( 2 , F ));
}
Return 0 ;
}