This can be solved using Maximum Flows. A similar (more complicated version) problem is available on LightOJ , and my code is for link
Here is the solution.
. no_rows, - no_cols.
no_rows + no_cols. no_rows ( "partite" ). l1, l2, ..., lno_row.
no_cols ( "partite" ). r1, r2, ... , rno_cols.
li rj 1 <= i <= no_rows
1 <= j <= no_cols, , 1.
(S) (T). , , .
, , .
. , li rj, , (i, j) 1, 0.
. , , (S, l) (r, T) .
: Dinic ++ ideone
2: , li, Ri ( R - , ). , Ri T, Ci ( C - , , )
source
share