# 【2011集训队出题】圈地计划

335人阅读 评论(0)

## 分析

var
n,m,t,i,j,k,x,y,nu,ans,pp,an:longint;
a1,b1,c,co:array[1..100,1..100] of longint;
q:array[1..4,1..2] of longint=((0,1),(1,0),(-1,0),(0,-1));
las,b,nex,f,a,dis:array[0..30000] of longint;
function min(l,r:longint):longint;
begin
if l<r then exit(l);exit(r);
end;
procedure insert(x,y,z,k:longint);
begin
inc(nu);b[nu]:=y;nex[nu]:=las[x];las[x]:=nu;f[nu]:=z;
inc(nu);b[nu]:=x;nex[nu]:=las[y];las[y]:=nu;f[nu]:=k;
end;
function bfs:boolean;
var l,r,p:longint;
begin
fillchar(dis,sizeof(dis),0);dis[0]:=1;l:=0;r:=1;a[1]:=0;
while l<r do begin
inc(l);p:=las[a[l]];
while p<>0 do begin
if (dis[b[p]]=0)and(f[p]>0) then begin
dis[b[p]]:=dis[a[l]]+1;inc(r);a[r]:=b[p];
end;p:=nex[p];
end;
end;
exit(dis[t]>0);
end;
function dinic(x,y:longint):longint;
var p,o:longint;
begin
if x=t then exit(y);
dinic:=0;p:=las[x];
while p<>0 do begin
if (dis[b[p]]=dis[x]+1)and(f[p]>0) then begin
o:=dinic(b[p],min(y,f[p]));
if o>0 then begin
dec(f[p],o);inc(f[p xor 1],o);inc(dinic,o);dec(y,o);
end;
end;p:=nex[p];
end;
end;
begin
for i:=1 to n do for j:=1 to m do begin read(a1[i,j]);ans:=ans+a1[i,j];end;
for i:=1 to n do for j:=1 to m do begin read(b1[i,j]);ans:=ans+b1[i,j];end;
for i:=1 to n do for j:=1 to m do read(c[i,j]);
for i:=1 to n do for j:=1 to m do if (i+j)mod 2=1 then co[i,j]:=1;
for i:=1 to n do
for j:=1 to m do begin
if co[i,j]=1 then begin insert(0,(i-1)*m+j,a1[i,j],0);insert((i-1)*m+j,t,b1[i,j],0);end
else begin insert(0,(i-1)*m+j,b1[i,j],0);insert((i-1)*m+j,t,a1[i,j],0);end;
for k:=1 to 4 do begin
x:=i+q[k,1];y:=j+q[k,2];
if (x<1)or(y<1)or(x>n)or(y>m) then continue;
insert((i-1)*m+j,(x-1)*m+y,c[i,j]+c[x,y],0);pp:=pp+c[i,j]+c[x,y];
end;
end;
while bfs do
an:=an+dinic(0,maxlongint);
writeln(ans+pp div 2-an);
end.
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：37292次
• 积分：1345
• 等级：
• 排名：千里之外
• 原创：93篇
• 转载：1篇
• 译文：0篇
• 评论：6条
文章分类
评论排行
最新评论