A classic composition: black-and-white staining of the lattice, dots for the XY section, respectively.
The side of the problem is a 2 of the land that can be sold, the end of which is the two points of X and y that occupy the land.
In this way, a binary map is built, and the answer to the most land requirement is clearly the maximum side independent set of the binary graph, which is the maximum match.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 using namespacestd;6 #defineMAXN 111117 #defineMAXM 1111118 #defineINF 1<<309 structedge{Ten intV,cap,flow,next; One }EDGE[MAXM]; A intVs,vt,ne,nv; - intHEAD[MAXN]; - the voidAddedge (intUintVintcap) { -Edge[ne].v=v; Edge[ne].cap=cap; edge[ne].flow=0; -Edge[ne].next=head[u]; head[u]=ne++; -Edge[ne].v=u; edge[ne].cap=0; edge[ne].flow=0; +EDGE[NE].NEXT=HEAD[V]; head[v]=ne++; - } + A intLEVEL[MAXN]; at intGAP[MAXN]; - voidBFs () { -memset (level,-1,sizeof(level)); -Memset (Gap,0,sizeof(GAP)); -level[vt]=0; -gap[level[vt]]++; inqueue<int>que; - Que.push (VT); to while(!Que.empty ()) { + intu=Que.front (); Que.pop (); - for(intI=head[u]; i!=-1; I=Edge[i].next) { the intv=edge[i].v; * if(level[v]!=-1)Continue; $level[v]=level[u]+1;Panax Notoginsenggap[level[v]]++; - Que.push (v); the } + } A } the + intPRE[MAXN]; - intCUR[MAXN]; $ intIsap () { $ BFS (); -memset (pre,-1,sizeof(pre)); -memcpy (Cur,head,sizeof(head)); the intu=pre[vs]=vs,flow=0, aug=INF; -gap[0]=NV;Wuyi while(level[vs]<NV) { the BOOLflag=false; - for(int&i=cur[u]; i!=-1; I=Edge[i].next) { Wu intv=edge[i].v; - if(Edge[i].cap!=edge[i].flow && level[u]==level[v]+1){ Aboutflag=true; $pre[v]=u; -u=v; - //aug= (Aug==-1?edge[i].cap:min (Aug,edge[i].cap)); -Aug=min (aug,edge[i].cap-edge[i].flow); A if(v==VT) { +flow+=; the for(u=pre[v]; V!=vs; v=u,u=Pre[u]) { -edge[cur[u]].flow+=; $edge[cur[u]^1].flow-=; the } the //Aug=-1; theaug=INF; the } - Break; in } the } the if(flag)Continue; About intMinlevel=NV; the for(intI=head[u]; i!=-1; I=Edge[i].next) { the intv=edge[i].v; the if(Edge[i].cap!=edge[i].flow && level[v]<minlevel) { +Minlevel=Level[v]; -cur[u]=i; the }Bayi } the if(--gap[level[u]]==0) Break; thelevel[u]=minlevel+1; -gap[level[u]]++; -u=Pre[u]; the } the returnflow; the } the - BOOLmap[111][111]; the intMain () { the intn,m,a,b,c; the while(~SCANF ("%d%d", &n,&m) && (n| |m)) {94memset (Map,0,sizeof(map)); thescanf"%d",&c); the while(c--){ thescanf"%d%d",&a,&b);98--a; --b; Aboutmap[a][b]=1; - }101Vs=n*m; vt=vs+1; nv=vt+1; Ne=0;102memset (head,-1,sizeof(head));103 for(intI=0; i<n; ++i) {104 for(intj=0; j<m; ++j) { the if((I+J) &1) Addedge (Vs,i*m+j,1);106 ElseAddedge (I*M+J,VT,1);107 if(Map[i][j])Continue;108 if(i+1<n &&!map[i+1][j]) {109 if((I+J) &1) Addedge (I*m+j, (i+1) *m+j,1); the ElseAddedge ((i+1) *m+j,i*m+j,1);111 } the if(j+1<m &&!map[i][j+1]){113 if((I+J) &1) Addedge (i*m+j,i*m+j+1,1); the ElseAddedge (i*m+j+1, I*m+j,1); the } the }117 }118printf"%d\n", ISAP ());119 } - return 0;121}
ZOJ1516 Uncle Tom's Inherited land (binary graph max match)