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
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 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. Then the next line 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). 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
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 Output +HINT
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=32
The data range of the problem is m<=20, so the first thought of the shape pressure, and then think of as if you want to preprocess all the path, in each time determined to go that, did not have the backbone of the puzzle, only know to deal with each time period of the shortest, and then dpt[i][j] The shortest path of the first day to the Y day F[1][j] initial value is F[j]*j,f[j]=min (f[j],f[i]+k+ (T[j+1][i]) * (I-J))
1#include <cstdio>2#include <cstring>3#include <iostream>4 #definell Long Long5 using namespacestd;6 Const intn= the;7 intq[n*2],dis[n],head[n];8 ll F[n],t[n][n];9 BOOLPd[n][n],inq[n],no[n];Ten intcnt,n,m,k,e1,d; One structee{intTo,next,w;} e[n*N]; A voidInsintUintVintW) { -e[++cnt].to=v,e[cnt].next=head[u],e[cnt].w=w,head[u]=CNT; -e[++cnt].to=u,e[cnt].next=head[v],e[cnt].w=w,head[v]=CNT; the } - - intSPFA (intXinty) { - intL=0, r=0; +memset (No,0,sizeof(No)); -memset (DIS,127/3,sizeof(DIS)); +memset (INQ,0,sizeof(INQ)); A for(inti=x;i<=y;i++) at for(intj=1; j<=m;j++)if(Pd[i][j]) no[j]=1; -dis[1]=0; q[++r]=1; - while(l<R) { - intnow=q[++l]; - for(intI=head[now];i;i=E[i].next) { - intv=e[i].to;if(No[v])Continue; in if(e[i].w+dis[now]<Dis[v]) { -dis[v]=e[i].w+Dis[now]; to if(!Inq[v]) { +q[++r]=v; -inq[v]=1; the } * } $ }Panax Notoginsenginq[now]=0; - } the returnDis[m]; + } A the voiddp () { + for(intI=1; i<=n;i++){ -f[i]= (LL) t[1][i]*i; $ for(intj=1; j<i;j++) $F[i]=min (f[i],f[j]+k+ (t[j+1][i]) * (I-j)); - } - } the - intMain () {Wuyiscanf"%d%d%d%d",&n,&m,&k,&E1); the intu,v,w,p,a,b; - for(intI=1; i<=e1;i++){ Wuscanf"%d%d%d",&u,&v,&W); - ins (u,v,w); About } $scanf"%d",&d); - for(intI=1; i<=d;i++){ -scanf"%d%d%d",&p,&a,&b); - for(intj=a;j<=b;j++) pd[j][p]=1; A } + for(intI=1; i<=n;i++) the for(intj=1; j<=n;j++) -t[i][j]=SPFA (i,j); $ DP (); theprintf"%lld", F[n]); the } the
"Bzoj 1003" [ZJOI2006] Logistics transport Trans