BZOJ 1003 物流运输trans
Description
物流公司要把一批货物从码头A运到码头B。由于货物量比较大,需要n天才能运完。货物运输过程中一般要转停好几个码头。物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪。由于各种因素的存在,有的时候某个码头会无法装卸货物。这时候就必须修改运输路线,让货物能够按时到达目的地。但是修改路线是一件十分麻烦的事情,会带来额外的成本。因此物流公司希望能够订一个n天的运输计划,使得总成本尽可能地小。
Input
第一行是四个整数n(1<=n<=100)、m(1<=m<=20)、K和e。n表示货物运输所需天数,m表示码头总数,K表示每次修改运输路线所需成本。接下来e行每行是一条航线描述,包括了三个整数,依次表示航线连接的两个码头编号以及航线长度(>0)。其中码头A编号为1,码头B编号为m。单位长度的运输费用为1。航线是双向的。再接下来一行是一个整数d,后面的d行每行是三个整数P( 1 < P < m)、a、b(1 < = a < = b < = n)。表示编号为P的码头从第a天到第b天无法装卸货物(含头尾)。同一个码头有可能在多个时间段内不可用。但任何时间都存在至少一条从码头A到码头B的运输路线。
Output
包括了一个整数表示最小的总成本。总成本=n天运输路线长度之和+K*改变运输路线的次数。
Sample Input
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
DP:f[i]表示前i天最小费用。先预处理出i-j天都走一样的路的最有方案(最短路)cost[i][j],在根据这个区间dp即可。
前三天走1-4-5,后两天走1-3-5,这样总成本为(2+2)*3+(3+2)*2+10=32
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<queue>
using namespace std; #define maxn 25
#define maxm 810
#define maxd 110
#define source (1)
#define sink (m)
int n,m,K,e,cnt,len[maxm*];
int side[maxn],toit[maxm*],next[maxm*];
long long cost[maxd][maxd],f[maxn];
bool block[maxn][maxd],in[maxn]; inline void add(int a,int b,int c)
{
next[++cnt] = side[a]; side[a] = cnt;
toit[cnt] = b; len[cnt] = c;
} inline void ins(int a,int b,int c) {add(a,b,c); add(b,a,c);} inline int spfa(int t1,int t2)
{
bool jud[maxn];
int dis[maxn];
memset(jud,true,sizeof(jud));
memset(dis,0x7,sizeof(dis));
int i,j,now;
for (i = ;i <= m;++i)
for (j = t1;j <= t2;++j)
if (block[i][j]) {jud[i] = false; break;}
queue <int> team;
in[source] = true; dis[source] = ; team.push(source);
while (!team.empty())
{
now = team.front(); team.pop();
for (i = side[now];i;i = next[i])
if (jud[toit[i]] && dis[toit[i]] > dis[now] + len[i])
{
dis[toit[i]] = dis[now] + len[i];
if (!in[toit[i]])
in[toit[i]] = true,team.push(toit[i]);
}
in[now] = false;
}
return dis[sink];
} int main()
{
freopen("1003.in","r",stdin);
freopen("1003.out","w",stdout);
scanf("%d %d %d %d",&n,&m,&K,&e);
int i,j;
for (i = ;i <= e;++i)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
ins(a,b,c);
}
int d; scanf("%d",&d);
while (d--)
{
int p,a,b; scanf("%d %d %d",&p,&a,&b);
for (i = a;i <= b;++i)
block[p][i] = true;
}
for (i = ;i <= n;++i)
for (j = i;j<=n;++j)
cost[i][j] = spfa(i,j);
for (i = ;i <= n;++i)
{
f[i] = (long long)i*cost[][i];
for (j = ;j < i;++j)
f[i] = min(f[i],K+f[j]+(i-j)*cost[j+][i]);
}
printf("%lld",f[n]);
fclose(stdin); fclose(stdout);
return ;
}
BZOJ 1003 物流运输trans的更多相关文章
- BZOJ 1003 物流运输trans dijstra+dp
1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3896 Solved: 1608[Submit] ...
- BZOJ 1003 物流运输 题解 【SPFA+DP】
BZOJ 1003 物流运输 题解 Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的 ...
- BZOJ 1003 物流运输 (动态规划 SPFA 最短路)
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5590 Solved: 2293 [Submit][Stat ...
- BZOJ 1003 物流运输 (dp + dijkstra)
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 8672 Solved: 3678[Submit][Stat ...
- [BZOJ]1003 物流运输(ZJOI2006)
挖坑,日常划水. 从BZOJ上的AC人数来看这题确实不难,但做这种题的常见思路让小C决定还是mark一下. Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才 ...
- BZOJ 1003 - 物流运输 - [最短路+dp]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1003 Time Limit: 10 Sec Memory Limit: 162 MB D ...
- BZOJ 1003 物流运输【最短路】【动态规划】
这道题数据太小啦!先枚举i,j表示从第i天到第j天不更改航线的费用. 然后直接跑最短路算法(我用的是Q版男朋友算法) 动归方程显然是f[i] = min(f[i], f[j] + cost[j+1][ ...
- BZOJ 1003 物流运输
最短路+dp. #include<iostream> #include<cstdio> #include<cstring> #include<algorith ...
- BZoj 1003 物流运输 DP+最短路
2013-09-11 09:56 W[I]代表前I天能取得的最小花费,假设在第J天更改一次路线,那么如果有 W[I]>W[J]+第j+1到第I天的最小花费+更改路线的花费(K) 那么更新W[I] ...
随机推荐
- the Linux Kernel: Traffic Control, Shaping and QoS
−Table of Contents Journey to the Center of the Linux Kernel: Traffic Control, Shaping and QoS 1 Int ...
- Linux下Wireshark普通用户不能获取网络接口问题
Linux下Wireshark普通用户不能获取网络接口问题 1.安装setcap, setcap 是libcap2-bin包的一部分,一般来说,这个包默认会已经装好. sudo apt-get ins ...
- C# StringExt 字符串扩展
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- js中跨域请求原理及2种常见解决方案
一.同源策略: 说到跨域请求,首先得说说同源策略: 1995年,同源政策是由 Netscape 公司引入浏览器的.目前,所有浏览器都实行了这个政策. 同源策略是浏览器的一种安全策略,所谓同源是指,域名 ...
- LAMP网站架构方案分析
本文引自:http://www.williamlong.info/archives/1908.html LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框 ...
- navicat 数据库管理工具快捷键
最近在使用navicat 管理数据库中,因为经常要写一些sql的,但是每次都要鼠标点击运行,感觉很不爽,于是找到navicat(以下) 快捷键(最常用的): ctrl + q 打开查询窗口 ctrl ...
- bootstrap 模态框关闭状态怎么获取
比如现在有个场景,一个事件 需要在模态框关闭之后再执行自己的逻辑,先上图: 参考官网说明:http://v3.bootcss.com/javascript/#modals-events //每次关闭模 ...
- Java-struts2 之值栈问题
这里是根据一个小项目,将数据库的值查出来,然后在页面前台进行遍历的方法 放入值的几种方式: Struts2的三种存值取值的方式 值栈: 栈上下文: ActionContext: package com ...
- jmeter压测app
使用代理的方式,录制app端脚本,之后用jmeter压测就没啥好说的了 1.电脑端谷歌设置本地代理(端口号为8888) 2.jmeter设置HTTP代理服务器(端口号为8888) 3.手机端wifi设 ...
- Android-The specified child already has a parent. You must call removeView() on the child's parent first.
这个问题搞了我半天了,网上有很多人说需要找到该控件的parent后,让该parent 先remove需要添加的控件,然后在添加,如: if (view != null) { ViewGroup par ...