ZJOI2006物流运输

时间:2023-03-09 03:43:24
ZJOI2006物流运输

唉,没想出来……

注意到预处理的作用。还有CLJ大牛说的话:这么小的数据,想干什么都可以。

SPFA预处理+DP 够经典

var
f:array[..,..]of longint;
a:array[..,..]of boolean;
head,next,go,w,q:array[..]of longint;
dis:array[..]of longint;
v,can:array[..]of boolean;
n,m,k,e,tot,l,r,h,t:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure spfa;
var
i,j,x:longint;
begin
h:=;
t:=;
q[]:=;
for i:= to m do
dis[i]:=;
dis[]:=;
for i:= to m do
v[m]:=false;
v[]:=true;
for i:= to m do
begin
can[i]:=true;
for j:=l to r do
if a[i,j] then can[i]:=false;
end;
while h<=t do
begin
inc(h);
x:=q[h];
v[x]:=false;
i:=head[x];
while i<> do
begin
j:=go[i];
if can[j] then
if dis[j]>dis[x]+w[i] then
begin
dis[j]:=dis[x]+w[i];
if v[x]=false then
begin
inc(t);
v[j]:=true;
q[t]:=j;
end;
end;
i:=next[i];
end;
end;
f[l,r]:=dis[m]*(r-l+);
end; procedure insert(x,y,z:longint);
begin
inc(tot);
go[tot]:=y;
next[tot]:=head[x];
head[x]:=tot;
w[tot]:=z;
end; procedure init;
var
i,j,x,y,z:longint;
begin
read(n,m,k,e);
for i:= to e do
begin
read(x,y,z);
insert(x,y,z);
insert(y,x,z);
end;
read(e);
fillchar(a,sizeof(a),false);
for i:= to e do
begin
read(x,y,z);
for j:=y to z do
a[x,j]:=true;
end;
for l:= to n do
for r:=l to n do
spfa;
end;
procedure dp;
var
i,j,l:longint;
begin
for i:= to n- do
for j:= to n-i do
for l:=j to i+j- do
f[j,i+j]:=min(f[j,i+j],f[j,l]+k+f[l+,i+j]);
write(f[,n]);
end; begin
init;
dp;
end.