Description
A class of the seat table is a n*m matrix, after a semester to get along, each classmate and left and right adjacent classmates to each other become good friends. This semester will be a penny of science, each classmate for the choice of arts and science have their own joy value, and a pair of good friends if you can choose arts or science, then they will harvest some joy value. As a computer competition coach of the SCP Big Boss, want to know how to allocate can make the whole class of joy value the largest sum.
Input
The first row of two positive integers n,m. Next is the six matrix the first matrix is n rows m column the number of row J of this matrix is the value of the students ' choice of the Humanities in column J of row I. The second matrix is n rows m column the number in column J of this matrix indicates the joy value that the classmate of the seat in column J of Row I has chosen for science. The third matrix is n-1 row m column the number in column J of this matrix indicates the additional joy value obtained by the students in row J of section I and the students of section J of Row I+1. The fourth matrix is a n-1 row m column the number in column J of this matrix indicates the additional joy value obtained by the students in column J of row I and the students of section J of Row I+1. The fifth matrix is n rows m-1 columns column I of row J of this matrix indicates that the students in column J of row I, and the students of row I of section j+1, choose the additional joy value obtained by the Liberal Arts. The sixth matrix is n rows m-1 columns column I of row J of this matrix indicates the additional joy value obtained by the students of the seat in column J of row I and the classmates in row I of section j+1.
Output
Outputs an integer that represents the maximum value of the sum of joy values
Sample Input1 2
1 1
100 110
1
1000
Sample Output1210
"Sample description"
When both men are chosen, they get the 100+110+1000 of joy.
"Data Size"
For data within 100%, n,m<=100 all Joy values are non-negative integers less than or equal to 5000
Hintsource
For the enhanced version of Hakata ...
First, this divides into two sets, then satisfies some conditions will have the income to seek the optimal allocation scheme the question
Generally consider the total income minus the minimum cut,
It is understood that all of these gains can be obtained, but to be divided into two sets, it is necessary to discard some edges so that the s,t is not connected (divided into two sets), to abandon the least, is the smallest cut;
For Bo more simple, as long as in the same set of income is the same, but the problem is slightly different;
In particular, the 2016 paper is very good ...
Made by qt666#include<cstdio> #include <algorithm> #include <cmath> #include <iostream># Include<cstring> #define RG registerusing namespace std;typedef long long ll;const int N=1000050;const int inf=19260 817;const double Eps=1e-5;int gi () {int x=0,flag=1; Char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') Flag=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') x=x*10+ch-' 0 ', Ch=getchar (); return X*flag;} int head[n],to[n],nxt[n],level[n],s,t,q[n*10],cnt=1,n,m,tt;double S[n],f;int id[200][200],a[200][200],b[200][200] , V1[200][200],v2[200][200],v3[200][200],v4[200][200];int valt;inline void Addedge (RG int x,rg int Y,RG double z) {To[++c nt]=y,s[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;} inline void lnk (RG int X,RG int Y,RG double z) {Addedge (x, Y, z), Addedge (y,x,0);} inline bool BFs () {for (RG int i=s;i<=t;i++) level[i]=0; Q[0]=s,level[s]=1;int T=0,sum=1; while (t<sum) {int x=q[t++]; if (x==t) return 1; for (RG int i=head[x];i;i=nxt[i]) { int y=to[i]; if (s[i]-0>=eps&&level[y]==0) {level[y]=level[x]+1;q[sum++]=y; }}} return 0;} Inline double dfs (RG int x,double maxf) {if (x==t) return MAXF; Double ret=0; for (RG int i=head[x];i;i=nxt[i]) {int y=to[i];d ouble f=s[i]; if (level[y]==level[x]+1&&f-0>=eps) {double minn=min (f,maxf-ret); F=dfs (Y,minn); S[i]-=f,s[i^1]+=f,ret+=f; if (RET==MAXF) break; }} if (!ret) level[x]=0; return ret;} inline void Dinic () {while (BFS ()) F+=dfs (S,inf);} int main () {N=gi (), M=gi (); s=0,t=n*m+1; for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m;j++) Id[i][j]=++tt; for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m;j++) A[i][j]=gi (), LNK (S,id[i][j],a[i][j]), valt+=a[i][j]; for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m;j++) B[i][j]=gi (), LNK (Id[i][j],t,b[i][j]), valt+=b[i][j]; for (int. i=1;i<=n-1;i++) for (RG int j=1;j<=m;j++) V1[i][j]=gi (), valt+=v1[i][j]; for (RG int i=1;i<=n-1;i++) For (RG int j=1;j<=m;j++) V2[i][j]=gi (), valt+=v2[i][j]; for (RG int i=1;i<=n-1;i++) for (RG int j=1;j<=m;j++) {lnk (s,id[i][j],v1[i][j]/2.0); LNK (s,id[i+1][j],v1[i][j]/ 2.0); LNK (id[i][j],t,v2[i][j]/2.0); lnk (id[i+1][j],t,v2[i][j]/2.0); LNK (Id[i][j],id[i+1][j], (V1[i][j]+v2[i][j])/2.0); LNK (Id[i+1][j],id[i][j], (V1[i][j]+v2[i][j])/2.0); } for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m-1;j++) V3[i][j]=gi (), valt+=v3[i][j]; for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m-1;j++) V4[i][j]=gi (), valt+=v4[i][j]; for (RG int i=1;i<=n;i++) for (RG int j=1;j<=m-1;j++) {lnk (s,id[i][j],v3[i][j]/2.0); LNK (s,id[i][j+1],v3[i][j]/ 2.0); LNK (id[i][j],t,v4[i][j]/2.0); lnk (id[i][j+1],t,v4[i][j]/2.0); LNK (Id[i][j],id[i][j+1], (V3[i][j]+v4[i][j])/2.0); LNK (Id[i][j+1],id[i][j], (V3[i][j]+v4[i][j])/2.0); } dinic ();p rintf ("%d\n", valt-(int) F); return 0;}
Bzoj 2127:happiness