Bzoj 2127 Happiness min cut

Source: Internet
Author: User

Topic: Given a seat map, adjacent to each other is a friend, each person chooses to learn the text or the theory will have the corresponding joy value, a pair of friends at the same time choose to learn the text/theory will also have the corresponding joy value, to seek the joy value and the largest program

The model of this problem is obviously the smallest cut--

See the relationship between neighboring points on the matrix it's easy to think of black-and-white staining, and then you can think of a color point sink swapped.

But it is a pity that I did not build a picture-I yy a practice but loved to find that the building method is not right-

Or Otz hzwer a little bit--http://hzwer.com/2422.html.

I don't have to repeat--

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 10100# Define S 0#define T (m*n+1) #define INF 0x3f3f3f3f#define P (i,j) ((i) *n-n+ (j)) using namespace Std;struct abcd{int To,f,next ;} Table[1001001];int head[m],tot=1;int m,n,ans;int a[110][110],b[110][100];void Add (int x,int y,int z) {table[++tot].to= Y;table[tot].f=z;table[tot].next=head[x];head[x]=tot;} void Link (int x,int y,int z) {Add (x, y, z); ADD (y,x,z);} namespace Max_flow{int Dpt[m];bool BFS () {static int q[m];int i,r=0,h=0;memset (dpt,-1,sizeof DPT);DP t[s]=1;q[++r]=s; while (r!=h) {int x=q[++h];for (i=head[x];i;i=table[i].next) if (table[i].f&&!~dpt[table[i].to]) {dpt[table[i ].to]=dpt[x]+1;q[++r]=table[i].to;if (table[i].to==t) return true;}} return false;} int dinic (int x,int flow) {int i,left=flow;if (x==t) return flow;for (I=head[x];i&&left;i=table[i].next) if ( table[i].f&&dpt[table[i].to]==dpt[x]+1) {int temp=dinic (table[i].to,min (LEFT,TABLE[I].F)); left-=temp; table[i].f-=Temp;table[i^1].f+=temp;} if (left) Dpt[x]=-1;return Flow-left;}} int main () {int i,j,x;cin>>m>>n;for (i=1;i<=m;i++) for (j=1;j<=n;j++) {scanf ("%d", &a[i][j]); ans +=a[i][j];a[i][j]<<=1;} for (i=1;i<=m;i++) for (j=1;j<=n;j++) {scanf ("%d", &b[i][j]); ans+=b[i][j];b[i][j]<<=1;} for (i=1;i<m;i++) for (j=1;j<=n;j++) {scanf ("%d", &x); ans+=x;a[i][j]+=x;a[i+1][j]+=x; Link (P (i,j), P (i+1,j), x);} for (i=1;i<m;i++) for (j=1;j<=n;j++) {scanf ("%d", &x); ans+=x;b[i][j]+=x;b[i+1][j]+=x; Link (P (i,j), P (i+1,j), x);} for (i=1;i<=m;i++) for (j=1;j<n;j++) {scanf ("%d", &x); ans+=x;a[i][j]+=x;a[i][j+1]+=x; Link (P (i,j), P (i,j+1), x);} for (i=1;i<=m;i++) for (j=1;j<n;j++) {scanf ("%d", &x); ans+=x;b[i][j]+=x;b[i][j+1]+=x; Link (P (i,j), P (i,j+1), x);} for (i=1;i<=m;i++) for (j=1;j<=n;j++) Link (s,p (i,j), a[i][j]), Link (P (i,j), t,b[i][j]), using namespace Max_flow; Ans<<=1;while (BFS ()) ans-=dinic (S,inf);cout<< (ans>>1) <<endl;return 0;}


Bzoj 2127 Happiness 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.