BZOJ2132 Rodeo Plan

Source: Internet
Author: User

BZOJ2132 Rodeo Plan

Test instructions

A piece of land can be divided into small areas of nxm blocks. Expire I row J column area, the construction business district will receive the AIJ income, the construction industrial area will obtain the bij income. If the region (I,J) is adjacent (adjacent to two squares with common edges) with a K block (obviously K not more than 4) the type is different from (i,j) area, then this area can increase KXCIJ revenue. The known gain matrix A,b,c, seeking the maximum value of income.

Exercises

Because the additional benefit is not between 22, consider dividing the problem by 2. The entire board is dyed in black and white due to the fact that two blocks of land are required for different properties. If a piece of land A is black, then s->a:c[a] a->t:c[a workers], if White is the opposite s->a:c[a workers] a->t:c[a), for the adjacent ab A<->b c[a and]+c[b together]. The final answer is all the gains and the least cuts.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineVisit (I,J) for (int i=g[j];i!=-1;i=es[i].n)7 #defineINF 0X3FFFFFFF8 using namespacestd;9 Ten structe{intT,c,n;}; E es[500000];intess,g[20000]; OneInlinevoidPeintFintTintc) {es[++ess]= (e) {t,c,g[f]}; g[f]=ess; es[++ess]= (e) {f,0, G[t]}; g[t]=ess;} AInlinevoidPe2 (intFintTintc) {es[++ess]= (e) {t,c,g[f]}; g[f]=ess; es[++ess]= (e) {f,c,g[t]}; g[t]=ess;} -InlinevoidInit () {ess=-1; memset (g,-1,sizeof(g));} -Queue <int> q;inth[20000]; the BOOLBFsintSintt) { -      while(! Q.empty ()) Q.pop (); memset (h,-1,sizeof(h)); Q.push (s); h[s]=0; -      while(!Q.empty ()) { -         intx=Q.front (); Q.pop (); +Visit (i,x)if(es[i].c&&h[es[i].t]==-1) {h[es[i].t]=h[x]+1; Q.push (es[i].t);} -     } +     if(h[t]==-1)return 0;Else return 1; A } at intDfsintXintTintf) { -     if(x==t)returnFintu=0; -Visit (i,x)if(es[i].c&&h[es[i].t]==h[x]+1){ -         intw=Dfs (Es[i].t,t,min (F,ES[I].C)); -F-=w; U+=w; Es[i].c-=w; es[i^1].c+=w;if(f==0)returnu; -     } in     if(!u) h[x]=-1;returnu; - } to intDinic (intSintT) {intf=0; while(BFS (s,t)) F+=dfs (S,t,inf);returnF;} + inta1[ $][ $],a2[ $][ $],a3[ $][ $],tot,n,m,s,t;BOOLcol[ $][ $]; -InlineintCgintXintY) {return(X-1) *m+y;} the intMain () { *scanf"%d%d", &n,&m); tot=0; $Inc (I,1, N) Inc (J,1, m) scanf ("%d", &a1[i][j]), tot+=A1[i][j];Panax NotoginsengInc (I,1, N) Inc (J,1, m) scanf ("%d", &a2[i][j]), tot+=A2[i][j]; -Inc (I,1, N) Inc (J,1, m) scanf ("%d",&a3[i][j]); thes=0; t=n*m+1; Init (); Inc (I,1, N) Inc (J,1, m) {col[i][j]= (i+j) &1;} +Inc (I,1, N) Inc (J,1, M) { A         if(Col[i][j]) PE (S,CG (I,J), A1[i][j]), PE (CG (I,J), t,a2[i][j]);Elsepe (S,CG (I,J), A2[i][j]), PE (CG (I,J), t,a1[i][j]); the         if(i!=n) Pe2 (CG (I,J), CG (i+1, j), a3[i][j]+a3[i+1][J]), tot+= (a3[i][j]+a3[i+1][j]); +         if(j!=m) Pe2 (CG (I,J), CG (i,j+1), a3[i][j]+a3[i][j+1]), tot+= (a3[i][j]+a3[i][j+1]); -     } $printf"%d", tot-dinic (s,t)); $     return 0; -}

20160324

BZOJ2132 Rodeo Plan

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.