这算是最小割中比较难的吧

看到选取显然最小割

看到上下左右四个点我感觉肯定和染色相关

注意每个点的收益获得条件是[或],因此我们考虑拆点i', i,分别表示通过四周控制和控制本身的代价

连边s-->i 流量为选择该点的代价; i-->i' 流量为该点的收益; i'到上下左右的j,流量为正无穷,表示另一个条件

这样,要获得收益便一定要割断一边,就满足了或的性质

注意,另一种颜色的连边与这种颜色相反,由于染色可以得到二分图

所以另一种颜色的连边反过来建即可

 const inf=;
dx:array[..] of longint=(,,-,);
dy:array[..] of longint=(,-,,); type node=record
po,next,flow:longint;
end; var e:array[..] of node;
numh,h,cur,p,pre,d:array[..] of longint;
a:array[..,..] of longint;
ans,i,j,x,y,len,t,n,m,k:longint; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y,f:longint);
begin
inc(len);
e[len].po:=y;
e[len].flow:=f;
e[len].next:=p[x];
p[x]:=len;
end; procedure build(x,y,f:longint);
begin
add(x,y,f);
add(y,x,);
end; function sap:longint;
var i,j,u,neck,tmp,q:longint;
begin
for i:= to t do
cur[i]:=p[i];
sap:=;
u:=;
neck:=inf;
numh[]:=t+;
while h[]<t+ do
begin
i:=cur[u];
d[u]:=neck;
while i<>- do
begin
j:=e[i].po;
if (e[i].flow>) and (h[u]=h[j]+) then
begin
neck:=min(neck,e[i].flow);
pre[j]:=u;
cur[u]:=i;
u:=j;
if u=t then
begin
sap:=sap+neck;
while u<> do
begin
u:=pre[u];
j:=cur[u];
dec(e[j].flow,neck);
inc(e[j xor ].flow,neck);
end;
neck:=inf;
end;
break;
end;
i:=e[i].next;
end;
if i=- then
begin
dec(numh[h[u]]);
if numh[h[u]]= then exit;
tmp:=t;
q:=-;
i:=p[u];
while i<>- do
begin
j:=e[i].po;
if e[i].flow> then
if h[j]<tmp then
begin
tmp:=h[j];
q:=i;
end;
i:=e[i].next;
end;
cur[u]:=q;
h[u]:=tmp+;
inc(numh[h[u]]);
if u<> then
begin
u:=pre[u];
neck:=d[u];
end;
end;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(n,m);
t:=*n*m+;
for i:= to n do
for j:= to m do
begin
read(x);
inc(k); a[i,j]:=k;
if (i+j) mod = then build(,a[i,j],x)
else build(a[i,j],t,x);
end; for i:= to n do
for j:= to m do
begin
read(x);
ans:=ans+x;
if (i+j) mod = then build(a[i,j],a[i,j]+n*m,x)
else build(a[i,j]+n*m,a[i,j],x);
end; for i:= to n do
for j:= to m do
begin
if (i+j) mod = then
begin
for k:= to do
begin
x:=i+dx[k];
y:=j+dy[k];
if (x<=) or (x>n) or (y<=) or (y>m) then continue;
build(a[i,j]+n*m,a[x,y],inf);
end;
end
else begin
for k:= to do
begin
x:=i+dx[k];
y:=j+dy[k];
if (x<=) or (x>n) or (y<=) or (y>m) then continue;
build(a[x,y],a[i,j]+n*m,inf);
end;
end;
end; writeln(ans-sap);
end.

bzoj3774的更多相关文章

  1. 【BZOJ3774】最优选择 最小割

    [BZOJ3774]最优选择 Description 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择 ...

  2. 【bzoj3774】最优选择 网络流最小割

    题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...

  3. bzoj3774 最优选择

    题目描述: 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bi ...

  4. Day5网络流

    算法 无源汇上下界可行流 先强制流过l的流量 从s到每个正权点连流量为l的流量 从每个负权点向t连-l的流量 如果容量为0,则不连边 有源汇上下界最大流 去掉下界 先求出可行流 再求S到T的最大流 有 ...

随机推荐

  1. sublime 修改Xdebug插件快捷键

    最近在用Xdebug插件 感觉挺好用 但是快捷键不太舒服,特别是调试下一步的时候,比较麻烦,按键较多: 所以想DIY下 但是preferences->package setting ->X ...

  2. 【刷机】Google Nexus s 蓝牙点击异常,无法启动,刷机解决方案

    1  问题详述 手头上有一部Google Nexus S ,本机自带的输入法不好用,想下载其他的输入法,想用蓝牙传输一下apk文件,点了一下蓝牙开关想要打开蓝牙功能,但奇怪的情况出现了,手机一直重启, ...

  3. mongodb命令使用

    最近学习mongodb的使用,整理了一些常用命令 windows服务安装:mongod --install --serviceName MongoDB --serviceDisplayName Mon ...

  4. CentOS 下 Codeblocks 的 安装 + 汉化 以及 基本使用介绍

    Codeblocks 安装 注:在root用户下运行下列命令 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可 yum install gcc yu ...

  5. dnf脚本的研究

    [player number] 2 8  [pvp start area]0 0 0 00 0 0 00 0 0 0[dungeon]62[/dungeon][type] `[normal]`[gre ...

  6. sql中的inner join, left join, right join的区别

    下面介绍一下 inner join, left join, right join这者之间的区别 现在我假设有A表和B表 left join select * from A a left join B ...

  7. iOS中的固定 高度

    iOS键盘高度   英文 216(不带联想功能) 英文 252(带联想功能)  中文 252 系统自带表情键盘的高度是 253   在使用系统键盘的时候,如果遇到输入框被键盘挡住的情况 就要用通知中心 ...

  8. 跨过slf4j和logback,直接晋级log4j 2

    今年一直关注log4j 2,但至今还没有出正式版.等不及了,今天正式向大家介绍一下log4j的升级框架,log4j 2. log4j,相信大家都熟悉,至今对java影响最大的logging系统,至今仍 ...

  9. (转)[C++语法] 关键字typedef用法

    转自http://www.cnblogs.com/SweetDream/archive/2006/05/10/395921.html C/C++语言中的typedef相信大家已经不陌生,本文对C/C+ ...

  10. JavaScript 踩坑心得— 为了高速(上)

    一.前言 很多情况下,产品的设计与开发人员一直想打造一套高品质的解决方案,从而快速.平稳地适应产品迭代.速度是衡量产品适应性的真正且唯一的标准,而且,这并不是笔者的一家之言. 「速度是衡量适应能力的真 ...