Title Description Description
The logistics company is going to ship a batch of cargo from Wharf A to Pier B. Due to the large volume of goods, it takes n days to complete the shipment. In the course of cargo transport, several terminals are generally diverted. Logistics companies typically design a fixed transport route to carry out strict management and tracking of the entire transport process. Due to the existence of various factors, sometimes a pier will not be able to load and unload goods. At this time, the transport route must be modified to allow the goods to arrive at their destination. But modifying the route is a very troublesome thing, and will bring additional costs. So logistics companies want to be able to order an N-day shipping plan, making the total cost as small as possible.
input/output format input/output
Input Format:
The first line is four integers n (l≤n≤100), M (l≤m≤20), K, and E. n indicates the number of days to transport the goods, m represents the total number of docks, and K indicates the cost of each modification of the shipping route. The next line of e lines is a description of the route, including three integers, which in turn represent the two port number of the route connection and the route length (>0). Pier A is numbered 1 and Pier B is M. The transportation cost per unit length is 1. The route is bidirectional. The next line is an integer d, followed by a line of D that is three integers P (1<p<m), A, B (1≤a≤b≤n). Indicates that the pier numbered P is unable to load and unload goods from day A to day B (including tail). The same dock may not be available for multiple time periods. But at any time there is at least one transport route from Pier A to Pier B.
output Format:
Includes an integer representing the minimum total cost. Total cost =n days the sum of the length of the transportation route +k* Change the number of shipping routes.
input and Output sample sample Input/output
sample Test point # #
Input Sample:
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
Sample output:
32
Description Description
"Sample Input description"
In turn, the 1th to the 5th day of the situation, the shadow indicates the pier is not available.
"Sample Output description"
The first three days go 1-4-5, after two days walk 1-3-5, so the total cost is (*3+) (3+2) *2+10=32.
_noi Guide 2010 Increase (01)
Single Source Shortest Way +DP
DIST[I,J] is a sustainable shortest path from day I to J Day
f[i,j]:=min{dist[1,i]*i,f[j]+dist[j+1,i]* (i-j) +k}
{Bereavement, Ruin your Life}
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 does begin num:=maxlongint; For I:=1 to M does 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 does 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-do-j:=1 to-do a[i,j]:=7000000; For I:=1-to-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 and D do can[t,j]:=false; End For I:=1 to N does for J:=i to n do begin Fillchar (cop,sizeof (COP), true); For U:=1 to M does 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.
[ZJOI2006] Logistics transport