BZOJ1003 Logistics Transportation

Source: Internet
Author: User

Test instructions: There are n days, M points, every day to go from 1 to M, some points can not be reached at some time, to ensure that every day there must be a road to M, each change route to spend K, to find the minimum cost of how much

This problem data range is very small, random mess.

Run a n^2 SPFA first, find out cost[i][j] (the minimum cost per day of the day to the first J Day)

One more DP will be done:

F[i]=min (f[i],f[j]+cost[j+1][i]* (i-j) +k);

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <queue>5 using namespacestd;6 structEdge {7     intv,next,w;8}e[2005];9 intk=1, N,m,e,d,kk;Ten inttim[ -][ the],avl[ -],dis[ -],vis[ the],head[2005],f[ the],cost[ the][ the]; One voidAdde (intUintVintW) { Ae[k].v=v;e[k].w=w;e[k].next=head[u];head[u]=k++; - } -Queue <int>Q; the intSPFA (intXinty) { -memset (DIS, the,sizeof(DIS)); -memset (AVL,0,sizeof(AVL)); -memset (Vis,0,sizeof(Vis)); +      for(intI=1; i<=m;i++) -          for(intj=x;j<=y;j++) +             if(Tim[i][j]) avl[i]=1; AQ.push (1); vis[1]=1;d is[1]=0; at      while(!Q.empty ()) { -         intU=q.front (); Q.pop (); vis[u]=0; -          for(intI=head[u];~i;i=E[i].next) { -             intv=e[i].v; -             if(!avl[v]&&dis[v]>dis[u]+E[I].W) { -dis[v]=dis[u]+E[I].W; in                 if(!Vis[v]) { -Q.push (v); vis[v]=1; to                 } +             } -         } the     } *     returnDis[m]; $ }Panax Notoginseng  - intMain () the { +memset (head,-1,sizeof(head)); AMemset (F, the,sizeof(f)); thef[0]=0; +scanf"%d%d%d%d",&n,&m,&kk,&E); -      for(intI=1, a,b,c;i<=e;i++) { $scanf"%d%d%d",&a,&b,&c); $ Adde (a,b,c); Adde (b,a,c); -     } -scanf"%d",&d); the      for(intI=1, p,a,b;i<=d;i++) { -scanf"%d%d%d",&p,&a,&b);Wuyi          for(intj=a;j<=b;j++) tim[p][j]=1; the     } -      for(intI=1; i<=n;i++) Wu          for(intj=1; j<=n;j++) -cost[i][j]=SPFA (i,j); About      for(intI=1; i<=n;i++) $          for(intj=0; j<i;j++) -             if(cost[j+1][i]!=0x3f3f3f3f) -F[i]=min (f[i],f[j]+cost[j+1][i]* (I-J) +KK); -printf"%d\n", f[n]-KK); A     return 0; +}
View Code

BZOJ1003 Logistics 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.