# [国家集训队]happiness 最小割 BZOJ 2127

• 第一个矩阵为n行m列

• 第二个矩阵为n行m列

• 第三个矩阵为n-1行m列

• 第四个矩阵为n-1行m列

• 第五个矩阵为n行m-1列

• 第六个矩阵为n行m-1列

## 输入输出样例

1 2
1 1
100 110
1
1000

1210


## 说明

【样例说明】

st--->A : A文+AB文/2，st--->B:B文+AB文/2；

A--->ed: A理+AB理/2，B--->ed：B理+AB理/2；

A<--->B:AB理/2+AB文/2；

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}

ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/

ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}

int n, m;
int st, ed;

struct node {
int u, v, w, nxt;
}edge[maxn<<1];

void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
}

int rk[maxn];

int bfs() {
queue<int>q;
ms(rk);
rk[st] = 1; q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
}

int dfs(int u, int flow) {
if (u == ed)return flow;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !(edge[i].w))continue;
if (!tmpadd) { rk[v] = -1; continue; }
}
}

int ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
}

int a[200][200], b[200][200], id[200][200];
int sum = 0;
void build() {
int x; st = 0; ed = n * m + 1;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= m; j++) {
rdint(x); sum += x;
a[i][j] += x; a[i + 1][j] += x;
}
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= m; j++) {
rdint(x); sum += x;
b[i][j] += x; b[i + 1][j] += x;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < m; j++) {
rdint(x); sum += x;
a[i][j] += x; a[i][j + 1] += x;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < m; j++) {
rdint(x); sum += x;
b[i][j] += x; b[i][j + 1] += x;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
}
}
}

int main()
{
//ios::sync_with_stdio(0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
rdint(a[i][j]); sum += a[i][j]; a[i][j] <<= 1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
rdint(b[i][j]); sum += b[i][j]; b[i][j] <<= 1;
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)id[i][j] = (i - 1)*m + j;
build(); dinic();
cout << sum - (ans >> 1) << endl;
return 0;
}


posted @ 2018-11-21 10:35  NKDEWSM  阅读(126)  评论(0编辑  收藏  举报