[ZJOI2006] Logistics and transportation

Source: Internet
Author: User

1003: [ZJOI2006] Logistics transport time limit:10 Sec Memory limit:162 MB
submit:5999 solved:2473
[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=32 The problem is obviously the shortest-circuiting, but the interesting thing is that the shortest-circuiting condition is limited. Watch the data range (1<=n<=100), M (1<=m<=20), I am this is a network flow? Yes, it's oi!. think crooked for a long time .... for effective maintenance conditions, it is easy to think of a cost[i][j] to represent the minimum cost from the source to the sink point from time I to J (solved with the shortest path algorithm, the data range determines that we can engage in brute force)with cost, isn't that the obvious DP model?define F[i] The total minimum cost before------time I. border f[0]=-k;initialization: F[j]=inf (1<=j<=n)Transfer equation: f[i]=min{f[i],f[j]+cost[j+1][i]* (i-j) +k} (0<=j<i)
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstdlib>5#include <algorithm>6#include <vector>7#include <cstring>8 #defineYyj (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout);9 #defineLLG Long LongTen #defineMAXN 110 OneLLG i,j,k,n,m,c[maxn][maxn],e,d,l,r,cost[maxn][maxn],head,tail,dl[maxn*Maxn],dis[maxn],js[maxn],f[maxn],kk; A using namespacestd; -Vector <llg>A[MAXN],VAL[MAXN]; - voidLink (llg x,llg y,llg z) {a[x].push_back (y); Val[x].push_back (z);} the BOOLPD (LLG x,llg i) - { -      for(Llg k=l;k<=r;k++)if(C[a[x][i]][k])return false; -     return true; + } - llg SPFA () + { Adis[1]=0; js[1]=1; at      for(i=2; i<=m;i++) {dis[i]=0x7fffffff; js[i]=0;} -Head=0; Tail=1; dl[1]=1; -      Do -     { -head++;  -LLG x=Dl[head]; injs[x]++;if(js[x]>m)return 0x7fffffff; -LLG w=a[x].size (); to          for(i=0; i<w;i++) +             if(Dis[a[x][i]]>dis[x]+val[x][i] &&PD (x,i)) -             { thetail++; *dl[tail]=A[x][i]; $dis[a[x][i]]=dis[x]+Val[x][i];Panax Notoginseng             } -} while(head!=tail); the     returnDis[m]; + } A intMain () the { +     //yyj ("a"); -Cin>>n>>m>>kk>>e; $      for(i=1; i<=e;i++) $     { - llg x, y, Z; -scanf"%lld%lld%lld",&x,&y,&z); the link (x, y, z); link (y,x,z); -     }WuyiCin>>D; the      for(i=1; i<=d;i++) -     { Wu LLG X,y,o; -scanf"%lld%lld%lld",&o,&x,&y); About          for(k=x;k<=y;k++) c[o][k]=1; $     } -      for(l=1; l<=n;l++) -          for(r=l;r<=n;r++) -cost[l][r]=SPFA (); AK=KK; f[0]=-K; +      for(i=1; i<=n;i++) f[i]=0x7fffffff; the      for(i=1; i<=n;i++) -          for(j=0; j<i;j++) $F[i]=min (f[i],f[j]+cost[j+1][i]* (I-J) +k); thecout<<F[n]; the     return 0; the}

[ZJOI2006] Logistics and transportation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.