1003: [ZJOI2006] Logistics transport time limit:10 Sec Memory limit:162 MB
submit:6331 solved:2610
[Submit] [Status] [Discuss] 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. The transport of goods in general to be transferred
Stop at several docks. Logistics companies typically design a fixed transport route to carry out strict management and tracking of the entire transport process. Due to various
Factors exist, 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 transport plan, making the total cost
As small as you can.
Input
The first line is four integers n (1<=n<=100), M (1<=m<=20), K, and E. n indicates the number of days to transport the goods, m indicates the total number of ports, K indicates
Cost per 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 terminals of the route connection
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. And Next
A row is an integer d, followed by a row of D for each row is three integers P (1 < P < m), A, B (1< = a < = b < = n). A code that is numbered p
The head from day A to day B can not load and unload goods (including tail). The same dock may not be available for multiple time periods. But at any time there is at least one
The transportation route from Pier A to Pier B.
Output
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.
Sample Input5 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 Output32
The first three days walk 1-4-5, after two days walk 1-3-5, so the total cost is () *3+ (3+2) *2+10=32First see the topic will think of the shortest way ... COST[I][J] indicates that the minimum cost per day from the day of the first to the J Day is to use SPFA to find the shortest. Set F[i] represents the minimum total cost of the first I day, then the state transition equation: f[i]=min{f[j]+cost[j+1][i]* (i-j) +k} (0<=j<i) initial value is F[i]=cost[1][i]*i, find out f[n] is the answer special reminder , the F array is set to long long, and it is also converted to long long when calculating f[i]=cost[1][i]*i
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <ctime>7#include <algorithm>8 using namespacestd;9 structnode{intY,next,v;} e[801];Ten Long Longn,m,k,p,d,len,link[ +],vis[ +],check[ +],dis[ +],f[101],q[5001],cost[101][101],flag[ +][101]; OneInlineintRead () A { - intx=0, f=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} the while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} - returnx*F; - } - voidInsertintXxintYyintVV) + { -e[++len].next=Link[xx]; +link[xx]=Len; Ae[len].y=yy; ate[len].v=VV; - } - intSPFA (intAintb) - { -memset (Vis,0,sizeof(Vis)); -memset (DIS,127/3,sizeof(DIS)); inmemset (check,0,sizeof(check)); - intHead=0, tail=0; toq[++tail]=1; vis[tail]=1; dis[tail]=0; + for(intI=1; i<=m;i++) - for(intj=a;j<=b;j++) the if(Flag[i][j]) check[i]=1; * while(++head<=tail) $ {Panax Notoginseng intnow=Q[head]; - for(intI=link[now];i;i=e[i].next) the { + if(!check[e[i].y]&&dis[now]+e[i].v<Dis[e[i].y]) A { thedis[e[i].y]=dis[now]+e[i].v; + if(!Vis[e[i].y]) - { $q[++tail]=e[i].y; $vis[e[i].y]=1; - } - } the } -vis[now]=0;Wuyi } the returnDis[m]; - } Wu intMain () - { About //freopen ("cin.in", "R", stdin); $ //freopen ("Cout.out", "w", stdout); -N=read (); M=read (); K=read (); p=read (); - for(intI=1; i<=p;i++) - { A intX=read (), Y=read (), z=read (); + Insert (x, y, z); Insert (y,x,z); the } -D=read (); $ for(intI=1; i<=d;i++) the { the intX=read (), Y=read (), z=read (); the for(intj=y;j<=z;j++) flag[x][j]=1; the } - for(intI=1; i<=n;i++) in for(intj=1; j<=n;j++) thecost[i][j]=SPFA (i,j); the for(intI=1; i<=n;i++) About { theF[i]= (Long Long) cost[1][i]*i; the for(intj=0; j<i;j++) theF[i]=min (f[i],f[j]+cost[j+1][i]* (I-J) +k); + } -printf"%lld", F[n]); the return 0;Bayi}
View Code
"Bzoj1003" [ZJOI2006] logistics and transportation