传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1003

预处理出第i天到第j天走一条航线时的最短路。

#include <cstdio>
#include <cstring>
#include <algorithm> const int maxn = 105, maxm = 25, maxe = 1005; int n, m, K, e, t1, t2, t3, dd;
int head[maxm], to[maxe << 1], next[maxe << 1], w[maxe << 1], lb;
int p[10005], a[10005], b[10005];
char book[maxm], inq[maxm];
int que[maxm], head_, tail, h, d[maxm], price[maxn][maxn];
int f[maxn]; inline void ist(int aa, int ss, int ww) {
to[lb] = ss;
next[lb] = head[aa];
head[aa] = lb;
w[lb] = ww;
++lb;
}
inline void spfa(int start, int end) {
memset(book, 0, sizeof book);
for (int i = 0; i < dd; ++i) {
if (a[i] <= end && b[i] >= start) {
book[p[i]] = 1;
}
}
if (book[1] || book[m]) {
price[start][end] = 0x3c3c3c3c;
return;
}
memset(que, 0, sizeof que);
memset(d, 0x3c, sizeof d);
memset(inq, 0, sizeof inq);
head_ = tail = 0;
que[tail++] = 1;
inq[1] = true;
d[1] = 0;
while (head_ != tail) {
h = que[head_++];
inq[h] = 0;
if (head_ == m) {
head_ = 0;
}
for (int j = head[h]; j != -1; j = next[j]) {
if (!book[to[j]] && d[to[j]] > d[h] + w[j]) {
d[to[j]] = d[h] + w[j];
if (!inq[to[j]]) {
inq[to[j]] = 1;
que[tail++] = to[j];
if (tail == m) {
tail = 0;
}
}
}
}
}
price[start][end] = d[m];
} int main(void) {
//freopen("in.txt", "r", stdin);
memset(next, -1, sizeof next);
memset(head, -1, sizeof head);
scanf("%d%d%d%d", &n, &m, &K, &e);
while (e--) {
scanf("%d%d%d", &t1, &t2, &t3);
ist(t1, t2, t3);
ist(t2, t1, t3);
}
scanf("%d", &dd);
for (int i = 0; i < dd; ++i) {
scanf("%d%d%d", p + i, a + i, b + i);
} for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
spfa(i, j);
}
}
f[0] = -K;
for (int i = 1; i <= n; ++i) {
f[i] = 2147483647;
for (int j = 0; j < i; ++j) {
if (price[j + 1][i] < 0x3c3c3c3c) {
f[i] = std::min(f[i], f[j] + price[j + 1][i] * (i - j));
}
}
f[i] += K;
}
printf("%d\n", f[n]);
return 0;
}

  

_bzoj1003 [ZJOI2006]物流运输【预处理】的更多相关文章

  1. bzoj1003[ZJOI2006]物流运输trans

    1003: [ZJOI2006]物流运输trans Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常 ...

  2. BZOJ 1003: [ZJOI2006]物流运输trans(最短路+dp)

    1A,爽! cost[i][j]表示从第i天到第j天不改路线所需的最小花费,这个可以用最短路预处理出.然后dp(i)=cost[j][i]+dp(j-1)+c. c为该路线的花费. --------- ...

  3. BZOJ_1003_[ZJOI2006]物流运输_最短路+dp

    BZOJ_1003_[ZJOI2006]物流运输_最短路+dp 题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1003 分析: 这种一段一段的显 ...

  4. 洛谷P1772 [ZJOI2006]物流运输

    P1772 [ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线 ...

  5. [ZJOI2006]物流运输 题解

    [ZJOI2006]物流运输 时间限制: 10 Sec  内存限制: 162 MB 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个 ...

  6. BZOJ 1003[ZJOI2006]物流运输(SPFA+DP)

    Problem 1003. -- [ZJOI2006]物流运输 1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: ...

  7. [ZJOI2006]物流运输(动态规划,最短路)

    [ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个 ...

  8. [ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5999  Solved: 2473[Submit][Stat ...

  9. bzoj1003 [ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6300  Solved: 2597[Submit][Stat ...

随机推荐

  1. Java处理XSS漏洞的工具类代码

    原文:http://www.open-open.com/code/view/1455809388308 public class AntiXSS { /** * 滤除content中的危险 HTML ...

  2. 【c++】拷贝控制具体分析

    我们可以定义拷贝操作,使类的行为看起来像一个值或者像一个指针,这取决于如何拷贝指针成员. 当我们拷贝一个像值的对象时,副本和原对象是完全独立的,改变副本不会对原对象有任何影响,反之亦然.标准库容器和s ...

  3. enumerateObjectsUsingBlock 、for 、for(... in ...) 的差别 &amp; 性能測试

    for VS for(... in ...) for 的应用范围广基本能够NSArray.NSArray以及C语言的数组等,而for(... in ...)仅限于NSArray.NSArray等 fo ...

  4. mysql中“Table ‘’ is read only”的解决办法

    之前是在linux下面直接Copy的data下面整个数据库文件夹,在phpMyAdmin里面重新赋予新用户相应权限后,drupal成功连接上数据库.但出现N多行错误提示,都是跟Cache相关的表是‘R ...

  5. APUE 线程 - 程序清单

    APUE 线程 - 程序清单 程序清单11-1 打印线程ID #include "util.h" #include<pthread.h> pthread_t ntid; ...

  6. Git撤销&amp;回滚操作

    开发过程中.你肯定会遇到这种场景: 场景一: 糟了.我刚把不想要的代码.commit到本地仓库中了.可是还没有做push操作! 场景二: 彻底完了.刚线上更新的代码出现故障了.须要还原这次提交的代码! ...

  7. 3 Angular 2 快速上手启动项目Demo

    Angular2.x与Angular1.x 的区别类似 Java 和 JavaScript 或者说是雷锋与雷峰塔的区别,想要运行Angular2需要安装一些第三方依赖,不会像Angular1.x那样, ...

  8. 6 使用Ionic开发天气应用

    简介:本节课我们会制作一款天气应用,这款应用允许用户查看当前的天气情况.天气预报以及地点收藏,在模态框内显示日出和日落的数据,使用分页滚动面板显示天气信息,使用侧滑菜单实现导航. 6.1 项目配置 环 ...

  9. 【java】itoo项目实战之hibernate 懒载入优化性能

    在做itoo 3.0 的时候,考评系统想要上线,就開始导入数据了,仅仅导入学生2万条数据,可是导入的速度特别的慢.这个慢的原因是由于导入的时候进行了过多的IO操作.可是导入成功之后,查询学生的速度更加 ...

  10. 用bis和bic实现位级操作

    20世纪70年代末至80年代末,DigitalEquipment的VAX计算机是一种非常流行的机型.它没有布尔运算AND和OR指令,仅仅有bis(位设置)和bic(位清除)这两种指令.两种指令的输入都 ...