bzoj3144
最小割解决最优值最突出的特点就是要将对象划分到两个集合中
这题很明显,裸的最小割
先把点连成一根根柱子,就是p(x,y,k)-->p(x,y,k+1)流量是P(x,y,k+1)的不和谐值
然后s与p(x,y,1)连边,流量是p(x,y,1)的不和谐值
最后再将p(x,y,r)都连向t
下面就是解决切割限制了,其实很简单,就是我们通过连边是不满足限制的点不构成一个割的方案
具体来说就是,对于任意p(x,y,k) (k<r) 连p(x',y',k+d)--->p(x,y,k) 流量inf,x',y'为邻居
画图可知正确性
const inf=;
dx:array[..] of longint=(,,-,);
dy:array[..] of longint=(,-,,); type node=record
flow,next,point:longint;
end; var edge:array[..] of node;
pre,p,cur,numh,h,d:array[..] of longint;
num:array[..,..,..] of longint;
l,w,n,m,r,k,j,t,len,x,y,i: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);
edge[len].point:=y;
edge[len].flow:=f;
edge[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 tmp,u,i,j,q,neck:longint;
begin
for i:= to t do
cur[i]:=p[i];
numh[]:=t+;
neck:=inf;
u:=;
sap:=;
while h[]<t+ do
begin
d[u]:=neck;
i:=cur[u];
while i<>- do
begin
j:=edge[i].point;
if (edge[i].flow>) and (h[u]=h[j]+) then
begin
pre[j]:=u;
cur[u]:=i;
neck:=min(neck,edge[i].flow);
u:=j;
if u=t then
begin
sap:=sap+neck;
while u<> do
begin
u:=pre[u];
j:=cur[u];
dec(edge[j].flow,neck);
inc(edge[j xor ].flow,neck);
end;
neck:=inf;
end;
break;
end;
i:=edge[i].next;
end;
if i=- then
begin
dec(numh[h[u]]);
if numh[h[u]]= then exit;
q:=-;
tmp:=t;
i:=p[u];
while i<>- do
begin
j:=edge[i].point;
if edge[i].flow> then
if h[j]<tmp then
begin
q:=i;
tmp:=h[j];
end;
i:=edge[i].next;
end;
h[u]:=tmp+;
inc(numh[h[u]]);
cur[u]:=q;
if u<> then
begin
u:=pre[u];
neck:=d[u];
end;
end;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(n,m,r);
readln(l);
t:=;
for k:= to r do
for i:= to n do
for j:= to m do
begin
read(x);
inc(t);
num[k,i,j]:=t;
build(num[k-,i,j],t,x);
end;
inc(t);
for i:= to n do
for j:= to m do
begin
build(num[r,i,j],t,inf);
for w:= to do
begin
x:=i+dx[w];
y:=j+dy[w];
if (x>) and (x<=n) and (y>) and (y<=m) then
begin
for k:= to r-l do
build(num[k+l,x,y],num[k,i,j],inf);
end;
end;
end; writeln(sap);
end.
bzoj3144的更多相关文章
- 【BZOJ3144】[HNOI2013]切糕
[BZOJ3144][HNOI2013]切糕 题面 题目描述 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑 ...
- 【BZOJ3144】切糕(网络流,最小割)
[BZOJ3144]切糕(网络流,最小割) 题面 BZOJ 题解 这样的类型很有趣 先不考虑相邻距离差不能超过\(D\)的限制 我们考虑答案,显然就是在每个位置选一个最小的高度割就行了 化成最小割的模 ...
- BZOJ3144 Hnoi2013 切糕 【网络流】*
BZOJ3144 Hnoi2013 切糕 Description Input 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的 ...
- 【BZOJ3144】[Hnoi2013]切糕 最小割
[BZOJ3144][Hnoi2013]切糕 Description Input 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q ...
- BZOJ3144/LG3227 「HNOI2013」切糕 最小割离散变量模型
问题描述 BZOJ3144 LG3227 还想粘下样例 输入: 2 2 2 1 6 1 6 1 2 6 2 6 输出: 6 题解 关于离散变量模型,我不想再抄一遍,所以: 对于样例,可以建立出这样的图 ...
- bzoj3144 [HNOI2013]切糕(最小割)
bzoj3144 [HNOI2013]切糕(最小割) bzoj Luogu 题面描述见上 题解时间 一开始我真就把这玩意所说的切面当成了平面来做的 事实上只是说相邻的切点高度差都不超过 $ d $ 对 ...
- Bzoj3144 [Hnoi2013]切糕
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1494 Solved: 818 Description Input 第一行是三个正整数P,Q,R,表 ...
- [BZOJ3144][HNOI2013]切糕(最小割)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3144 分析:神题不解释 http://www.cnblogs.com/zig-zag/ ...
- 【BZOJ-3144】切糕 最小割-最大流
3144: [Hnoi2013]切糕 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1261 Solved: 700[Submit][Status] ...
随机推荐
- bash 脚本
一.英文版 1.Advanced Bash-Scripting Guide 二.中文 1.BashGuide for Beginners 中文版
- Date、String、Calendar类型之间的转化
原文出处:http://fjfj910.iteye.com/blog/1202219 1.Calendar 转化 String //获取当前时间的具体情况,如年,月,日,week,date,分,秒等 ...
- UDP TCP应用场景
作者:陈硕链接:https://www.zhihu.com/question/20060141/answer/26735814来源:知乎著作权归作者所有,转载请联系作者获得授权. UDP 的使用范围很 ...
- django1.6之创建用户
如何你运行python manager.py syncdb(数据库同步成功) 则运行一下代码 >>> from django.contrib.auth.models import U ...
- 【BZOJ】1046 : [HAOI2007]上升序列
1046: [HAOI2007]上升序列 题意:给定S={a1,a2,a3,…,an}问是否存在P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且 ...
- shell写的计算器
#!/bin/bashif [ $# -ne 3 ] then echo "Usage: $0 num1 + num2" fi case $2 in +) echo $1$2$3= ...
- LocalContainerEntityManagerFactoryBean
http://doc.okbase.net/liuyitian/archive/109276.html
- Unity3d Shader开发(一)Properties
着色器可以定义一个参数列表,可以由开发者在材质检视面板编辑参数.着色器文件中的Properties块定义了这些参数: 语法: Properties { Property [Property ...] ...
- DEPRECATED: Use of this script to execute hdfs command is deprecated.
DEPRECATED: Use of this script to execute hdfs command is deprecated. 本人安装的hadoop版本是2.4.0的,但每次执行命令时都 ...
- 防止横竖屏时,iphone自动缩放的一段js代码
function orientation_change() { var viewport = document.querySelector('meta[name="viewport& ...