Bzoj 3894 min cut of arts and Sciences Division

Source: Internet
Author: User

The main topic: give a table, each person to choose liberal arts or science, everyone choose a liberal arts have a satisfaction, choose science has a satisfaction, to a person center of five people all choose a subject also has a satisfaction degree. Ask what is the maximum satisfaction level.


Idea: Later to see the Arts and Sciences division, such as 80% should be the smallest cut.

Add up all the answers first, then subtract the maximum flow after the build is the answer.

S-> Everyone f: This person chooses the degree of satisfaction of the liberal arts

Everyone->t f: This person chooses the degree of satisfaction of science

For each person to create more than two new points, respectively, the point as the center of the five points all selected liberal arts and science. Note that these two points are S1 and S2.

S1-> Five points centered on this point f:inf

One point for the center of the Five Points->s2 F:inf

And then the bare smallest cut.


CODE:

#define _crt_secure_no_warnings#include <queue> #include <cstdio> #include <cstring> #include < iostream> #include <algorithm> #define MAX 1000010#define maxp 30010#define INF 0x3f3f3f3f#define S 0#define T (MA XP-1) using namespace Std;const int dx[] = {0,1,-1,0,0};const int dy[] = {0,0,0,1,-1};struct Maxflow{int head[maxp],total ; int Next[max],aim[max],flow[max];int DEEP[MAXP]; Maxflow (): Total (1) {}void Add (int. x,int Y,int f) {next[++total] = head[x];aim[total] = Y;flow[total] = f;head[x] = total;} void Insert (int x,int y,int f) {Add (x,y,f); ADD (y,x,0);} BOOL BFS () {static queue<int> Q;while (!q.empty ()) Q.pop () memset (deep,0,sizeof (deep));d eep[s] = 1;q.push (S); while (!q.empty ()) {int x = Q.front (), Q.pop (), for (int i = head[x]; i; i = Next[i]) if (Flow[i] &&!deep[aim[i]) {de Ep[aim[i]] = deep[x] + 1;q.push (Aim[i]), if (aim[i] = = T) return true;}} return false;} int dinic (int x,int f) {if (x = = T) return F;int temp = f;for (int i = head[x]; i; i = Next[i]) if (flow[I] && deep[aim[i]] = = Deep[x] + 1 && temp) {int away = Dinic (Aim[i],min (Temp,flow[i])); if (!away) deep[aim[i ]] = 0;flow[i]-= away;flow[i^1] + = away;temp-= away;} return f-temp;}}  Solver;int m,n;int ina[max],outa[max];int num[110][110],cnt;int Main () {cin >> m >> n;for (int i = 1; I <= m;  ++i) for (int j = 1; J <= N, ++j) num[i][j] = ++cnt;int ans = 0;for (int i = 1; I <= m; ++i) for (int x,j = 1; j <= N; ++J) {scanf ("%d", &x); ans + = x;solver. Insert (s,num[i][j] * 3,x);} for (int i = 1; I <= m; ++i) for (int x,j = 1; j <= N; ++j) {scanf ("%d", &x); ans + = x;solver. Insert (num[i][j] * 3,t,x);} for (int i = 1; I <= m; ++i) for (int x,j = 1; j <= N; ++j) {scanf ("%d", &x); ans + = x;solver.  Insert (S,num[i][j] * 3 + 1,x); for (int k = 0; k <= 4; ++k) {int FX = i + dx[k],fy = j + dy[k];if (!fx | |!fy | | FX > M || FY > N) continue;solver. Insert (Num[i][j] * 3 + 1,num[fx][fy] * 3,inf);}} for (int i = 1, i <= m; ++i) for (int x,j = 1; j <= N; ++j) {SCANF ("%d", &x); ans + = x;solver.  Insert (Num[i][j] * 3 + 2,t,x); for (int k = 0; k <= 4; ++k) {int FX = i + dx[k],fy = j + dy[k];if (!fx | |!fy | | FX > M || FY > N) continue;solver. Insert (Num[fx][fy] * 3,NUM[I][J] * 3 + 2,inf);}} int max_flow = 0;while (solver. BFS ()) Max_flow + = Solver. Dinic (S,inf); cout << Ans-max_flow << endl;return 0;}


Bzoj 3894 min cut of arts and Sciences Division

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.