传送门: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;
}

  

转载于:https://www.cnblogs.com/ciao-sora/p/6165862.html

_bzoj1003 [ZJOI2006]物流运输【预处理】相关推荐

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

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

  2. BZOJ1003: [ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 8800  Solved: 3747 [Submit][St ...

  3. BZOJ 1003: [ZJOI2006]物流运输trans

    二次联通门 : BZOJ 1003: [ZJOI2006]物流运输trans /*BZOJ 1003: [ZJOI2006]物流运输transSpfa + DpSpfa预处理出i到j天的最小花费然后N ...

  4. bzoj 1003: [ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 7819  Solved: 3273 [Submit][St ...

  5. P1772 [ZJOI2006]物流运输(线性dp+最短路径)

    P1772 [ZJOI2006]物流运输 题意 [ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头 A 运到码头 B.由于货物量比较大,需要 nnn 天才能运完.货物运输过程中一般要转 ...

  6. 【bzoj1003】[ZJOI2006]物流运输 最短路+dp

    传送门:嘿原题在这 题意:给出一个图,求1-m的最短路,但其中有些点在某些时间段会不能用,题目保证有解. 我们可以很(不)容易的看出递推关系式dp[i]=min(dp[i],dp[j]+cost[j+ ...

  7. P1772 [ZJOI2006]物流运输

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

  8. 【洛谷 - P1772 】[ZJOI2006]物流运输(dp)

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

  9. [ZJOI2006]物流运输

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

最新文章

  1. scipy/python quad()数值积分
  2. docker安装elasticsearch和kibana
  3. Adobe Reader 背景色修改
  4. python display update用不了能用filp_疯狂的Pygame——使用python写游戏(yuyu版)——基础讲解部分——第一章...
  5. python发送json数据_在Websockets上发送JSON
  6. 控制dcom程序使用端口_使用VS Code调试.net控制台应用程序的方法
  7. html5仿腾讯,高仿腾讯QQ Xplan(X计划)的H5页面(1):threejs创建地球
  8. JSP:src路径里有中文,产生乱码问题
  9. 系统集成资质 - 案例分析与常规题答案
  10. Python+Selenium学习--异常截图
  11. Harris角点检测算法手动实现
  12. Github 爆火!程序员疯抢的 Java 面试宝典(PDF 版)限时开源
  13. Git报错:Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch
  14. 值对象 Value Object
  15. request爬虫爬取电影并利用pyqt5进行本地播放(失败品)
  16. matlab运算放大器仿真,利用Matlab分析运算放大器电路.doc
  17. stm32-W5500-官网教程
  18. 2017暴雪php,动视暴雪2017Q4财报 开启全新里程碑
  19. 魅族设置语音录音服务器,魅族手机留言录音功能使用方法介绍
  20. docker(七)容器与外部通信

热门文章

  1. WebRTC笔记之二十二:基于WebRTC的视频聊天室—QHTalkGenius
  2. 聊天室html布局,h5聊天室模板|仿微信聊天室html5
  3. ISO14000系列标准特点(转载)
  4. 环状序列(Circular Sequence,ACM/ICPC Seoul 2004,UVa1584)
  5. DTFT, DFT, FFT 的区别、联系和特点
  6. win 和linux
  7. R5F102AAASP#X0集成电路 嵌入式 微控制器RENESAS R5F102AAASP#30
  8. 防患于未然 将“流氓”挡在系统之外(转)
  9. 前端图片在线压缩的网站
  10. 怎样用计算机自带软件打电话,教你电脑怎么打电话