题面

中文题面…

BZOJ 传送门

Luogu 传送门

分析

这道题类似于BZOJ 3774 最优选择,然后这里有一篇博客写的很好…

Today_Blue_Rainbow’s Blog

应该看懂了吧…不懂的画画图,分分情况会发现…这连边…好妙啊

CODE

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
template<typename T>inline void read(T &num) {
char ch; while((ch=getchar())<'0'||ch>'9');
for(num=0;ch>='0'&&ch<='9';num=num*10+ch-'0',ch=getchar());
}
const int inf = 1e9;
const int MAXN = 30005;
const int MAXM = 2000005;
const int dx[] = { 1, -1, 0, 0, 0 };
const int dy[] = { 0, 0, -1, 1, 0 };
int n, m, fir[MAXN], S, T, cnt;
struct edge { int to, nxt, c; }e[MAXM];
inline void add(int u, int v, int cc) {
e[cnt] = (edge){ v, fir[u], cc }; fir[u] = cnt++;
e[cnt] = (edge){ u, fir[v], 0 }; fir[v] = cnt++;
}
int dis[MAXN], vis[MAXN], info[MAXN], cur, q[MAXN];
inline bool bfs() {
int head = 0, tail = 0;
vis[S] = ++cur; q[tail++] = S;
while(head < tail) {
int u = q[head++];
for(int i = fir[u]; ~i; i = e[i].nxt)
if(e[i].c && vis[e[i].to] != cur)
vis[e[i].to] = cur, dis[e[i].to] = dis[u] + 1, q[tail++] = e[i].to;
}
if(vis[T] == cur) memcpy(info, fir, (T+1)<<2);
return vis[T] == cur;
}
int dfs(int u, int Max) {
if(u == T || !Max) return Max;
int flow=0, delta;
for(int &i = info[u]; ~i; i = e[i].nxt)
if(e[i].c && dis[e[i].to] == dis[u] + 1 && (delta=dfs(e[i].to, min(e[i].c, Max-flow)))) {
e[i].c -= delta, e[i^1].c += delta, flow += delta;
if(flow == Max) return flow;
}
return flow;
}
inline int dinic() {
int flow=0, x;
while(bfs()) {
while((x=dfs(S, inf))) flow+=x;
}
return flow;
}
int art[105][105], sci[105][105], same_a[105][105], same_s[105][105];
inline int enc(int i, int j, int k) { return (i-1)*m + j + k*n*m; }
int main () {
memset(fir, -1, sizeof fir);
read(n), read(m); S = 0; T = n*m*3+1; int sum = 0;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) read(art[i][j]);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) read(sci[i][j]);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) read(same_a[i][j]);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) read(same_s[i][j]);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) {
add(S, enc(i, j, 0), art[i][j]); sum += art[i][j];
add(enc(i, j, 0), T, sci[i][j]); sum += sci[i][j];
add(S, enc(i, j, 1), same_a[i][j]); sum += same_a[i][j];
add(enc(i, j, 2), T, same_s[i][j]); sum += same_s[i][j];
for(int l = 0, x, y; l < 5; ++l)
if((x=i+dx[l]) >= 1 && x <= n && (y=j+dy[l]) >= 1 && y <= m) {
add(enc(i, j, 1), enc(x, y, 0), inf);
add(enc(x, y, 0), enc(i, j, 2), inf);
}
}
printf("%d\n", sum-dinic());
}

BZOJ 3894 / Luogu P4313 文理分科 (拆点最小割)的更多相关文章

  1. BZOJ 3894 Luogu P4313 文理分科 (最小割)

    题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=3894 (luogu) https://www.luogu.org/pro ...

  2. Luogu P4313 文理分科

    link 最小割 双倍经验 这道题运用了最小割最常用的一种用法:集合划分. 因为源汇最小割即就是将源汇划分到不同的集合,那么最简单的应用就是最小代价划分集合了. 本题中,题意是将 \(n\cdot m ...

  3. 【题解】 bzoj3894: 文理分科 (网络流/最小割)

    bzoj3894,懒得复制题面,戳我戳我 Solution: 首先这是一个网络流,应该还比较好想,主要就是考虑建图了. 我们来分析下题面,因为一个人要么选文科要么选理科,相当于两条流里面割掉一条(怎么 ...

  4. BZOJ3894/LG4313 文理分科 新建点最小割

    问题描述 BZOJ3894 LG4313 题解 显然一个人只能选文/理 -> 一个人只能属于文(S).理(T)集合中的一个 可以把选择文得到 \(art\) 的收益看做选择文失去 \(scien ...

  5. P1345 [USACO5.4]奶牛的电信[拆点+最小割]

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  6. UVA1660 电视网络 Cable TV Network[拆点+最小割]

    题意翻译 题目大意: 给定一个n(n <= 50)个点的无向图,求它的点联通度.即最少删除多少个点,使得图不连通. 解析 网络瘤拆点最小割. 定理 最大流\(=\)最小割 感性地理解(口胡)一下 ...

  7. P4313 文理分科 最小割

    $ \color{#0066ff}{ 题目描述 }$ 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用一个n*m的矩阵进行描述,每个格 ...

  8. [bzoj3532][Sdoi2014]Lis——拆点最小割+字典序+退流

    题目大意 给定序列A,序列中的每一项Ai有删除代价Bi和附加属性Ci.请删除若 干项,使得4的最长上升子序列长度减少至少1,且付出的代价之和最小,并输出方案. 如果有多种方案,请输出将删去项的附加属性 ...

  9. BZOJ 1585: Earthquake Damage 2 地震伤害 网络流 + 最小割

    Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着两个牧场Ai和Bi,注意可能有很多条道路连接着相同的Ai和Bi,并且Ai有可能和Bi相等.F ...

随机推荐

  1. ASP.NET请求过程-Handler

    什么事Handler asp.net程序所有的请求都是handler处理的.以前的webform我们访问的地址是xxxxx.aspx地址,其实他也会到一个handler(我们写的业务代码都在handl ...

  2. Selenium绕过登录的实现

    1.使用命令行启动Chrome:Mac:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -remote-debugging ...

  3. Centos7.3安装jdk和maven

    安装jdk和maven             通过winscp上传jdk             解压                 tar -zxvf jdk-8u91-linux-x64.ta ...

  4. Error:Could not find method google() for arguments [] on repository container

    Error:Could not find method google() for arguments [] on repository container. Consult IDE log for m ...

  5. 判断pdf文件是否正常可用

    之前在下载港交所的文件的时候会碰到有些文件异常的情况,文件下载下来,但是不能打开.查到其他的方法不是判断错误就是很麻烦.   整理出一个非常简单的方法,将文件以二进制方式打开,然后判断文件的开头是否符 ...

  6. 怎样获取当前对象的原型对象prototype

    1. 使用 Object.getPrototypeOf(); function Person(name){ this.name = name; } var lilei = new Person(&qu ...

  7. win10 右键新建卡顿

    前段时间不知道自己搞啥了,右键变得很慢,找了一些常规的解决方案,什么清除注册表等等的,对我来说,没好用. 然后将就继续使用,然后觉得是office的问题,卸载,重装2010的,发现还是一样卡... 继 ...

  8. WPF 自定义一个控件,当点击按钮是触发到ViewModel(业务逻辑部分)和Xaml路由事件(页面逻辑部分)

    #region - 用于绑定ViewModel部分 - public ICommand Command { get { return (ICommand)GetValue(CommandPropert ...

  9. jQuery_了解jQuery

  10. POJ1083(Moving Tables)--简单模拟

    题目链接:http://poj.org/problem?id=1083 如图所示在一条走廊的两侧各有200个房间,现在给定一些成对的房间相互交换桌子,但是走廊每次只能通过一组搬运, 也就是说如果两个搬 ...