BZOJ1003: [ZJOI2006] Logistics Transportation SPFA+DP

Source: Internet
Author: User
1003: [ZJOI2006] Logistics and transportationTime Limit:10 Sec Memory limit:162 MB submit:6284 solved:2588 [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

The

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 Input 5 5 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
//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 : Find the shortest possible short circuit and then DP on it

#include <cstdio> #include <cstring> #include <queue> using namespace std;
const int m=1005;
const int n=105;
int n,m,k,d[n],t[n][n],f[n];
BOOL Flag[n][n],inq[n],xie[n];
int to[m],nxt[m],lj[n],w[m],cnt;
	void Add (int f,int t,int p) {cnt++;
	to[cnt]=t;
	NXT[CNT]=LJ[F];
	lj[f]=cnt;
W[cnt]=p;
} queue<int>q; int SPFA (int s,int t) {while (!
	Q.empty ()) Q.pop ();
	for (int i=0;i<=21;i++) d[i]=100000;
	memset (Xie,0,sizeof (Xie));
	memset (inq,0,sizeof (INQ));
	for (int i=s;i<=t;i++) for (int j=1;j<=m;j++) if (flag[i][j]) xie[j]=1;
	Inq[1]=1;
	d[1]=0;
	Q.push (1); while (!
		Q.empty ()) {int X=q.front ();
		Q.pop ();
			for (int i=lj[x];i;i=nxt[i]) if (!xie[to[i]]&&d[to[i]]>d[x]+w[i]) {d[to[i]]=d[x]+w[i];
				if (!inq[to[i]]) {Q.push (to[i]);
			Inq[to[i]]=1;
	}} inq[x]=0;
} return d[m];
	} int main () {int q,x,y,z,d;
	scanf ("%d%d%d%d", &n,&m,&k,&q);
	    for (int i=1;i<=q;i++) {scanf ("%d%d%d", &x,&y,&z); Add(x, y, z); 
 	Add (y,x,z);
	} scanf ("%d", &d);
		for (int i=1;i<=d;i++) {scanf ("%d%d%d", &x,&y,&z);
	for (int j=y;j<=z;j++) flag[j][x]=1;
	} for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) T[I][J]=SPFA (I,J);
		for (int i=1;i<=n;i++) {f[i]=t[1][i]*i;
	for (int j=0;j<i;j++) f[i]=min (f[i],f[j]+k+t[j+1][i]* (i-j));
} printf ("%d\n", F[n]);
 }

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.