Test Instructions:Link
Method: SPFA+DP
parsing: Good topic, because the data range is small, so it can be done in this way, but it is very difficult to think about. We define cost (I,J) to indicate the minimum costs of using the same method from day I to J days, and then because the data is smaller, we define f[i] to represent the minimum cost for the first I day. And then we can write the transfer equation. F[i ] =mINF [I],F [J]+K +CosT(J+1,I) J is smaller than I. And then you can go over the water! Incidentally, when calculating cost (j+1,i), consider the preprocessing of each restricted section, that is, which points can go in these days.
Code:
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N#define M 10100#define INF 0x3f3f3f3fusing namespace STD;intn,m,k,e,d,cnt;intV[n],can[n],f[n];structnode{intto;intNextintVal;} EDGE[M];intHead[n],dis[n];structlimit{intP,a,b;} L[M];//f[i]=max (C (1,i), F[j]+k+c (J+1,i));voidInit () {memset(head,-1,sizeof(head)); Cnt=1;}voidEdgeadd (intFromintTo,intval) {edge[cnt].to=to; Edge[cnt].val=val; Edge[cnt].next=head[from]; head[from]=cnt++;}intCostintLeintRI) {memset(CAN,0,sizeof(can)); for(intI=1; i<=d;i++) {if(Max (LE,L[I].A) <=min (ri,l[i].b)) can[l[i].p]=1; }memset(Dis,0x3f,sizeof(dis));memset(V,0,sizeof(v)); Queue<int>Q Q.push (1); v[1]=1; dis[1]=0; while(!q.empty ()) {intU=q.front (); Q.pop (); v[u]=0; for(inti=head[u];i!=-1; i=edge[i].next) {intto=edge[i].to;if(Can[to])Continue;if(Dis[u]+edge[i].val<dis[to]) {dis[to]=dis[u]+edge[i].val;if(!v[to]) {Q.push (to); v[to]=1; } } } }if(Dis[m]==inf)returnINF;returndis[m]* (ri-le+1);}intMain () {init ();scanf("%d%d%d%d", &n,&m,&k,&e); for(intI=1; i<=e;i++) {intX, Y, Zscanf("%d%d%d", &x,&y,&z); Edgeadd (x, y, z); Edgeadd (Y,X,Z); }scanf("%d", &d); for(intI=1; i<=d;i++)scanf("%d%d%d", &l[i].p,&l[i].a,&l[i].b); for(intI=1; i<=n;i++) {F[i]=cost (1, i); for(intj=1; j<i;j++) {F[i]=min (F[i],f[j]+k+cost (j+1, i)); } }printf("%d\n", F[n]);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 1003 [ZJOI2006] Logistics transport Trans SPFA+DP