Very classical network flow model, the row and column respectively as a point, rows and columns and see the capacity, the lower bound is 1, so first minus 1, after the addition of the good.
Forward to the star map, the printing solution will be more troublesome.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = the;structedge{intV,cap,flow;}; Vector<Edge>edges;#definePB push_backVector<int>G[MAXN];voidAddedge (intUintVintc) {G[u]. PB (Edges.size ()); Edges. PB (Edge{v,c,0}); G[V]. PB (Edges.size ()); Edges. PB (Edge{u,0,0});}Const intINF =0x3f3f3f3f;ints,t;intvcnt;BOOLVIS[MAXN];intD[MAXN];intq[maxn<<1];BOOLBFs () {memset (Vis,0,sizeof(BOOL)*vcnt); intL =0, r =0; Q[r+ +] = S; Vis[s] =true; while(r>l) { intU = q[l++]; for(inti =0; I < g[u].size (); i++) {Edge&e =Edges[g[u][i]]; if(!VIS[E.V] && e.cap >E.flow) {VIS[E.V]=true; D[E.V]= d[u]+1; Q[r++] =e.v; } } } returnvis[t];}intCUR[MAXN];intDfsintUinta) { if(U = = t| |! AreturnA; intFlow =0, F; for(int&i = Cur[u]; I < g[u].size (); i++) {Edge&e =Edges[g[u][i]]; if(D[E.V] = = d[u]+1&& (f = DFS (E.v,min (a,e.cap-e.flow))) >0) {E.flow+=F; Edges[g[u][i]^1].flow-=F; Flow+=F; A-=F; if(!a) Break; } } returnflow;}intMaxflow () {intFlow =0; while(BFS ()) {memset (cur,0,sizeof(int)*vcnt); Flow+=DFS (S,inf); } returnflow;}Const intN = -;intRid[n],cid[n];voidinit () {vcnt=2; Edges.clear ();}intMain () {//freopen ("In.txt", "R", stdin);S =0; T =1; intTestCase; scanf"%d",&testCase); intmcnt =0; while(testcase--) {init (); intR,c,cap,pre; scanf"%d%d",&r,&b); for(inti =0, M = r+c+2; i < M; i++) g[i].clear (); Pre=0; for(inti =0; i < R; i++) {Rid[i]= vcnt++; scanf ("%d",&cap); Addedge (S,rid[i],cap-pre-b); Pre=cap; } Pre=0; for(inti =0; i < C; i++) {Cid[i]= vcnt++; scanf ("%d",&cap); Addedge (Cid[i],t,cap-pre-R); Pre=cap; } for(inti =0; i < R; i++) for(intj =0; J < C; J + +) {Addedge (rid[i],cid[j], +); } maxflow (); printf ("Matrix%d\n",++mcnt); for(inti =0; i < R; i++){ intK =0, U =Rid[i]; for(intj =0; J < G[u].size (); J + +) {Edge&e =Edges[g[u][j]]; if(E.V = =Cid[k]) {printf ("%d%c", e.flow+1, ++k==c?'\ n':' '); if(k = = C) Break; } } } if(testCase) Putchar ('\ n'); } return 0;}
UVA-11082 Matrix decompressing