题目描述 Description
物流公司要把一批货物从码头A运到码头B。由于货物量比较大,需要n天才能运完。货物运输过程中一般要转停好几个码头。物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪。由于各种因素的存在,有的时候某个码头会无法装卸货物。这时候就必须修改运输路线,让货物能够按时到达目的地。但是修改路线是—件十分麻烦的事情,会带来额外的成本。因此物流公司希望能够订一个n天的运输计划,使得总成本尽可能地小。
标签:
题目描述 Description
5 5 10 8
1 2 1
1 3 3
1 4 2
2 3 2
2 4 4
3 4 1
3 5 2
4 5 2
4
2 2 3
3 1 1
3 3 3
4 4 5
说明 description
【样例输入说明】
单源最短路+DP
cop[i]=true 为第i天可连续使用
dist[i,j]为从第i天到第j天的可持续的最短路
f[i,j]:=min{dist[1,i]*i,f[j]+dist[j+1,i]*(i-j)+k}
code:
var a:array[1..20,1..20]of int64;
b,c,d,n,m,e,s:int64;
i,j,k,u,t:longint;
can:array[1..20,1..100]of boolean;
dis:array[1..100,1..100]of int64;
cop:array[1..20]of boolean;
f:array[1..100]of int64;
function min(a,b:longint):longint;begin if a<b then exit(a)else exit(b)end;
function getmin(s1,s2:longint):longint;
var i,j,k,num,s:longint;
f:array[1..20]of longint;
bo:array[1..20]of boolean;
begin
for i:=1 to m do f[i]:=7000000;
fillchar(bo,sizeof(bo),false);
bo[s1]:=false;f[s1]:=0;
while bo[s2]=false do
begin
num:=maxlongint;
for i:=1 to m do
if (bo[i]=false)and(cop[i]=true)and(f[i]<num) then
begin num:=f[i];s:=i;end;
bo[s]:=true;
for i:=1 to m do if (f[s]+a[s,i]<f[i])and(cop[i]) then f[i]:=f[s]+a[s,i];
end;
exit(f[s2]);
end;
begin
read(n,m,k,e);
for i:=1 to 20 do for j:=1 to 20 do a[i,j]:=7000000;
for i:=1 to 20 do a[i,i]:=0;
for i:=1 to e do
begin
read(c,d,s);
a[c,d]:=s;
a[d,c]:=s;
end;
read(s);
fillchar(can,sizeof(can),true);
for i:=1 to s do
begin
read(t,c,d);
for j:=c to d do can[t,j]:=false;
end;
for i:=1 to n do
for j:=i to n do
begin
fillchar(cop,sizeof(cop),true);
for u:=1 to m do for t:=i to j do cop[u]:=cop[u] and can[u,t];
dis[i,j]:=getmin(1,m);
end;
for i:=1 to n do
begin
f[i]:=dis[1,i]*i;
for j:=1 to i-1 do f[i]:=min(f[i],f[j]+dis[j+1,i]*(i-j)+k);
end;
writeln(f[n]);
end.
标签:
原文地址:http://www.cnblogs.com/spiderKK/p/4886497.html