Bzoj 3894: Division of Arts and Sciences [min Cut]

Source: Internet
Author: User

3894: Liberal Arts division time limit:10 Sec Memory limit:512 MB
submit:674 solved:392
[Submit] [Status] [Discuss] Description Science and Arts Division is a very tangled matter! (Although people who see this topic certainly have not tangled up) small p in the class to carry out the arts and Sciences Division. His class can be described by a n*m matrix, each of which represents a classmate's seat. Each student must choose a subject from the arts and sciences. Students will get a satisfactory value when they choose the subject. The satisfaction value is obtained as follows: 1. If the classmate of line I second J chooses the liberal arts, he will get art[i][j] satisfaction value, if choose Science, will get SCIENCE[I][J] satisfaction value. 2. If the students in row J of line I chose the liberal arts, and he was next to each other (two squares and only if they had an identical edge), all the students chose the liberal arts, he would be happier, so he would increase same_art[i][j] satisfaction. 3.  If the students in row J of Line I chose science, and all of his classmates chose science, the satisfaction value of same_science[i]j[] was increased. Small p wants to know how people should choose, in order to make all people's satisfaction value and maximum. Please tell him the maximum value.

Input first behavior two positive integers: N,m next n technique m Integer, representing Art[i][j]; next n the number of M integers. SCIENCE[I][J]; next n the M integer, which indicates that the same_art[i][j];output output is an integer representing the maximum satisfactory value of the sum of sample Input3 4
13 2 4 13
7 13 8 12
18 17 0 5

8 13 15 4
11 3 8 11
11 18 6 5

1 2 3 4
4 2 3 2
3 1 0 4

3 2 3 2
0 2 2 1
0 2 4 4Sample Output theHint Sample description
1 The choice of liberal arts, 0 for the selection of science, the programme is as follows:
1 0 0 1
0 1 0 0
1 0 0 0 n,m<=100, read-in data are <=500 a person either choose the text, or choose the reason, must give up aIf there is no adjacent mysterious bonus, direct:The satisfaction value of s----------- the satisfaction of-->tso now there's a mystery bonus, how to cut this thing off .for the mysterious addition of the arts, build a point even s capacity for the entire selection of satisfactory value, this point even four weeks of human capacity INF, so that the satisfaction and those who are satisfied with the value of the candidate must have a cutScience Note Even for four weeks, you have to be yourself .
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=3e4+5, m=2e5+5, inf=1e9;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intn,m,num,s,t,a,b,c;structedge{intV,c,f,ne;} E[m<<1];intCnt,h[n];inlinevoidInsintUintVintc) {//printf ("Ins%d%d%d\n", u,v,c);cnt++; E[CNT].V=v;e[cnt].c=c;e[cnt].f=0; e[cnt].ne=h[u];h[u]=CNT; CNT++; E[CNT].V=u;e[cnt].c=0; e[cnt].f=0; e[cnt].ne=h[v];h[v]=CNT;}intQ[n],head,tail,vis[n],d[n];BOOLBFs () {memset (Vis,0,sizeof(VIS)); memset (d,0,sizeof(d)); Head=tail=1; D[s]=0; vis[s]=1; Q[tail++]=s;  while(head!=tail) {        intu=q[head++];  for(intI=h[u];i;i=e[i].ne) {            intv=e[i].v; if(!vis[v]&&e[i].c>e[i].f) {Vis[v]=1; D[V]=d[u]+1; Q[tail++]=v; if(v==t)return true; }        }    }    return false;}intCur[n];intDfsintUinta) {    if(u==t| | a==0)returnA; intflow=0, F;  for(int&i=cur[u];i;i=e[i].ne) {        intv=e[i].v; if(d[v]==d[u]+1&& (F=dfs (V,min (A,E[I].C-E[I].F)) >0) {Flow+=F; E[I].F+=F; e[((i-1)^1)+1].f-=F; A-=F; if(a==0) Break; }    }    returnflow;}intDinic () {intflow=0;  while(BFS ()) { for(inti=s;i<=t;i++) cur[i]=H[i]; Flow+=DFS (S,inf); }    returnflow;} InlineintIdintIintj) {return(I-1) *m+J;}intans;intMain () {//freopen ("In.txt", "R", stdin);N=read (); m=read (); Num=n*m; S=0; t=num*3+1;  for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) A=read (), Ins (S,id (I,J), a), ans+=A;  for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) B=read (), Ins (ID (i,j), t,b), ans+=b;  for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {C=read ();intK=id (I,J) +num;ans+=B;        Ins (s,k,c);        Ins (K,id (I,J), INF); if(I-1>=1) Ins (K,id (i-1, J), INF); if(j+1<=m) Ins (K,id (i,j+1), INF); if(i+1<=n) Ins (K,id (i+1, J), INF); if(J-1>=1) Ins (K,id (i,j-1), INF); }     for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {C=read ();intK=id (I,J) +num+num;ans+=B;        Ins (k,t,c);        INS (ID (i,j), k,inf); if(I-1>=1) Ins (ID (i-1, J), K,inf); if(j+1&LT;=M) Ins (ID (i,j+1), K,inf); if(i+1<=n) Ins (ID (i+1, J), K,inf); if(J-1>=1) Ins (ID (i,j-1), K,inf); } printf ("%d", ans-dinic ());}

Bzoj 3894: Division of Arts and Sciences [min Cut]

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.