传送门: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. 基于51单片机的CAN通讯协议C语言程序

      //-----------------------函数声明,变量定义-------------------------------------------------------- #includ ...

  2. the attribute buffer size is too small 解决方法

    在进行查询的时候引发The attribute buffer size is too small错误解决 http://bbs.esrichina-bj.cn/esri/viewthread.php? ...

  3. 偏差-方差分解Bias-Variance Decomposition

    转自: http://www.cnblogs.com/jmp0xf/archive/2013/05/14/Bias-Variance_Decomposition.html

  4. socket的bind函数是不是只能绑定本地IP,不能绑定外网IP么?

    参考: https://bbs.csdn.net/topics/391024376 别瞎猜测. 所谓bind,就是指绑定本地接受端口. 指定ip,是为了分辨多ip主机. --------------- ...

  5. Centos5.11 //IP/phpmyadmin 远程无法登入

    异地登入phpmyadmin时,会出现"You don't have permission to access /phpmyadmin/ on this server."这是因为配 ...

  6. [Javascript] Understanding the .constructor property on JavaScript Objects

    Constructor functions hold an interesting purpose in JavaScript. Unlike in classical languages, they ...

  7. 【OpenGL】Shader实例分析(七)- 雪花飘落效果

    转发请保持地址:http://blog.csdn.net/stalendp/article/details/40624603 研究了一个雪花飘落效果.感觉挺不错的.分享给大家,效果例如以下: 代码例如 ...

  8. Guice 学习(八)AOP (面向切面的编程)

    Guice的AOP还是非常弱的.眼下只支持方法级别上的,另外灵活性也不是非常高. 看例如以下演示样例: Guice支持AOP的条件是: 类必须是public或者package (default) 类不 ...

  9. oracle授权、表备份、用户管理

    用户管理 创建用户: create user 用户名 identified by 密码; 修改用户密码: alter user 用户名 identified by 密码; 激活用户: alter us ...

  10. MJRefresh实现刷新(使用它的Block方法)

    MJRefresh实现刷新(使用它的Block方法)   // // YFMVCPostListViewController.m // iOS122 // // Created by 颜风 on 15 ...