传送门: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. javascript 语法规范错误提示代码

    “Missing semicolon.” : “缺少分号.”, “Use the function form of \”use strict\”.” : “使用标准化定义function.”, “Un ...

  2. 从CakePHP 1.3升级到2.5

    从CakePHP 1.3升级到2.5 摘要:最近把一个CakePHP 1.3的项目升级到了2.x,当然就用最新的版本2.5.3了,结果基本满意.本文记录了升级的过程,包括使用的工具,遇到的问题和相应的 ...

  3. C 编程中fseek、ftell的用法总结

    fseek 函数功能是将文件指针移动到指定的地方,因此可以通过fseek重置文件指针的位置.函数原型: int  fseek(FILE *stream, long offset,  int origi ...

  4. 返回模式有流式(streaming)和整体(total) 热词词表解决方案

    重要术语说明_语音识别(ASR)_智能语音交互-阿里云  https://help.aliyun.com/document_detail/72238.html 返回模式(response mode) ...

  5. XMU 1071 圣斗士黄金十二宫(七)银河星爆 【计算几何】

    1071: 圣斗士黄金十二宫(七)银河星爆 Time Limit: 500 MS  Memory Limit: 64 MBSubmit: 193  Solved: 10[Submit][Status] ...

  6. 《CMake实践》笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE【转】

    本文转载自:http://www.cnblogs.com/52php/p/5681745.html 前言: 开发了5,6年的时间,如果没有KDE4,也许不会有人或者Linux发行版本重视cmake,因 ...

  7. Visual C++ 2010入门教程

    <Visual C++ 2010入门教程>系列一:关于Visual Studio.VC和C++的那些事   作者:董波 日期:2010.6.14 写在前面 在我还在上学的时候,我选择了C+ ...

  8. HDU1402:A * B Problem Plus(FFT与大数乘法)

    Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: th ...

  9. Servlet单例非安全解析

    Servlet容器默认是采用单实例多线程的方式处理多个请求 Servlet容器<Web容器<应用服务器?apache<tomcat<websphere Servlet不是线程安 ...

  10. Tensorflow卷积接口总结

    tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 这个接口用了这么久,每次都有点迷惑,这里 ...