标签:状态压缩 space ++ for style pap front nod 示意图
ZJOI物流运输
物流公司要把一批货物从码头A运到码头B。由于货物量比较大,需要n天才能运完。货物运输过程中一般要转停好几个码头。物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪。由于各种因素的存在,有的时候某个码头会无法装卸货物。这时候就必须修改运输路线,让货物能够按时到达目的地。但是修改路线是一件十分麻烦的事情,会带来额外的成本。因此物流公司希望能够订一个n天的运输计划,使得总成本尽可能地小。
样例示意图
图中依次表示第一至五天的情况。红色表示不可用的码头
5 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
32 前三天走1-4-5,后两天走1-3-5,这样总成本为(2+2)*3+(3+2)*2+10=32
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
vector<int> choose,cost;
queue<int> Q;
struct node {
int next,to,w;
}edge[505];
int n,m,ch,e,cnt=0,head[25],dis[25],g[105][105],f[105];
bool inq[25],bad[25][101],no[25];
inline void add(int x,int y,int w) {
edge[++cnt].to=y;
edge[cnt].w=w;
edge[cnt].next=head[x];
head[x]=cnt;
}
int SPFA() {
memset(dis,127,sizeof(dis));
memset(inq,0,sizeof(inq));
dis[1]=0;
Q.push(1);
int x;
while(!Q.empty()) {
x=Q.front();
inq[x]=0;
Q.pop();
for(int i=head[x];i;i=edge[i].next)
if((!no[edge[i].to])&&dis[x]+edge[i].w<dis[edge[i].to]) {
dis[edge[i].to]=dis[x]+edge[i].w;
if(!inq[edge[i].to]) {
inq[edge[i].to]=1;
Q.push(edge[i].to);
}
}
}
if(dis[m]>1e9) return 1e6;
return dis[m];
}
int main() {
int x,y,w,d,p;
scanf("%d%d%d%d",&n,&m,&ch,&e);
while(e--) {
scanf("%d%d%d",&x,&y,&w);
add(x,y,w);
add(y,x,w);
}
scanf("%d",&d);
while(d--) {
scanf("%d%d%d",&p,&x,&y);
for(int j=x;j<=y;j++) bad[p][j]=1;
}
for(int i=1;i<=n;i++) {
memset(no,0,sizeof(no));
for(int j=i;j<=n;j++) {
for(int k=2;k<m;k++) no[k]|=bad[k][j];
g[i][j]=SPFA();
}
}
for(int i=1;i<=n;i++) {
f[i]=2e9;
for(int j=0;j<i;j++) f[i]=min(f[i],f[j]+g[j+1][i]*(i-j)+ch);
}
printf("%d\n",f[n]-ch);
return 0;
}
标签:状态压缩 space ++ for style pap front nod 示意图
原文地址:http://www.cnblogs.com/the-unbeatable/p/6973725.html