"Bzoj" "1003" "ZJOI2006" logistics transport Trans

Source: Internet
Author: User

Shortest Way/DP

The data size is not BIG!! This is the point ...

So the direct violence DP is good: F[i] represents the minimum cost for the first I day, then there is $f[i]=min\{f[j]+cost[j+1][i]+k\} (0\leq J \leq i-1) $ where the expense array represents the L day to the R day is only used in a single transport scheme for continuous operation $r-l+ 1$ the minimum cost of the day, because N is very small, so the violent enumeration L, R, with the shortest-path algorithm to calculate ...

Remember to open long long

1 /**************************************************************2 problem:10033 User:tunix4 language:c++5 result:accepted6 time:52 Ms7 memory:1396 KB8 ****************************************************************/9  Ten //Bzoj 1003 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at     intv=0, sign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } - Const intn= the, m= +, inf=100000000; intypedefLong LongLL; - /******************tamplate*********************/ to intto[m],next[m],head[n],len[m],cnt; + voidInsintXintYintz) { -To[++cnt]=y; NEXT[CNT]=HEAD[X]; head[x]=cnt; len[cnt]=Z; the } * voidAddintXintYintz) { $ ins (x, y, z); ins (y,x,z);Panax Notoginseng } - /*******************edge************************/ the intn,m,k,e; + LL F[n],cost[n][n],d[n]; A intQ[m]; the BOOLCan[n][n],vis[n],inq[n]; + LL SPFA () { -     intL=0, r=-1; $F (I,2, m) d[i]=INF; $d[1]=0; inq[1]=1; -q[++r]=1; -      while(l<=R) { the         intx=q[l++]; -inq[x]=0;Wuyi          for(intI=head[x];i;i=Next[i]) the             if(Vis[to[i]] && d[to[i]]>d[x]+Len[i]) { -d[to[i]]=d[x]+Len[i]; Wu                 if(!Inq[to[i]]) { -q[++r]=To[i]; Aboutinq[to[i]]=1; $                 } -             } -     } -     returnD[m]; A } +   the intMain () { - #ifndef Online_judge $Freopen ("1003.in","R", stdin); theFreopen ("1003.out","W", stdout); the #endif theN=getint (); M=getint (); K=getint (); E=getint (); the     intx, y, z -F (I,1, E) { inX=getint (); Y=getint (); z=getint (); the Add (x, y, z); the     } About     intq=getint (); theF (I,1, M) F (J,1, N) can[i][j]=1; theF (I,1, Q) { theX=getint (); Y=getint (); z=getint (); +F (j,y,z) can[x][j]=0; -     } theF (I,1, N) F (j,i,n) {BayiF (x,1, m) vis[x]=1; theF (x,2, M-1) F (K,I,J)if(!can[x][k]) vis[x]=0; theCOST[I][J]=SPFA () * (j-i+1); -     } -F (I,1, N) f[i]=cost[1][i]; theF (I,1, N) F (J,0, I-1) F[i]=min (f[i],f[j]+cost[j+1][i]+k); theprintf"%lld\n", F[n]); the     return 0; the } - 
View Code 1003: [ZJOI2006] Logistics transport trans Time limit:10 Sec Memory limit:162 MB
submit:3956 solved:1638
[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

Source [Submit] [Status] [Discuss]

"Bzoj" "1003" "ZJOI2006" logistics transport Trans

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.