Topic links
1003: [ZJOI2006] Logistics transport trans Time limit:10 Sec Memory limit:162 MB
submit:5246 solved:2157
[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. 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
n^2 [I, J] days, the shortest from 1 to N, and then the DP. Dp[i] = min (dp[i], dp[j-1]+dis[j][i]+k), specific look at the code, very good understanding.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Const intMAXN = 1e5+5;inthead[maxn*2], num, N, M, K, E, D, Dis[maxn], val[ the][ the], DP[MAXN], VIS[MAXN];structnode{intto, Nextt, W;} E[MAXN*2];structxx{intL, R, POS;} A[MAXN];voidAddintUintVintW) {e[num].to= V, e[num].nextt = head[u], E[NUM].W = W, head[u] = num++;}intcan[ -];voidinit () {num=0; Mem1 (head);}voidCheckintLintr) {mem (CAN); for(inti =0; i<d; i++) { if(A[i].l>r | | a[i].r<l)Continue; Can[a[i].pos]=1; }}intSPFA () {Queue<int>Q; MEM2 (DIS); Mem (VIS); dis[1] =0, vis[1] =1; Q.push (1); while(!Q.empty ()) { intU =Q.front (); Q.pop (); Vis[u]=0; for(inti = Head[u]; ~i; i =e[i].nextt) { intv =e[i].to; if(Can[v])Continue; if(dis[v]>dis[u]+E[I].W) {Dis[v]= dis[u]+E[I].W; if(!Vis[v]) {Vis[v]=1; Q.push (v); } } } } returndis[m];}intMain () {intx, y, Z; CIN>>n>>m>>k>>E; Init (); for(inti =0; i<e; i++) {scanf ("%d%d%d", &x, &y, &z); Add (x, y, z); Add (y, x, z); } CIN>>D; for(inti =0; i<d; i++) {scanf ("%d%d%d", &a[i].pos, &A[I].L, &A[I].R); } mem2 (Val); for(inti =1; i<=n; i++) { for(intj = i; j<=n; J + +) {Check (I, j); VAL[I][J]=SPFA (); }} mem2 (DP); dp[0] =0; for(inti =1; i<=n; i++) { for(intj =1; j<=i; J + +) { if(Val[j][i] >= inf | | dp[j-1] >=inf)Continue; Dp[i]= Min (Dp[i], dp[j-1]+val[j][i]* (i-j+1)+k); }} cout<<dp[n]-k<<Endl; return 0;}
Bzoj 1003: [ZJOI2006] Logistics transport Trans shortest Road +DP