_bzoj1003 [ZJOI2006]物流运输【预处理】
传送门: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]物流运输【预处理】的更多相关文章
- bzoj1003[ZJOI2006]物流运输trans
1003: [ZJOI2006]物流运输trans Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常 ...
- BZOJ 1003: [ZJOI2006]物流运输trans(最短路+dp)
1A,爽! cost[i][j]表示从第i天到第j天不改路线所需的最小花费,这个可以用最短路预处理出.然后dp(i)=cost[j][i]+dp(j-1)+c. c为该路线的花费. --------- ...
- BZOJ_1003_[ZJOI2006]物流运输_最短路+dp
BZOJ_1003_[ZJOI2006]物流运输_最短路+dp 题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1003 分析: 这种一段一段的显 ...
- 洛谷P1772 [ZJOI2006]物流运输
P1772 [ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线 ...
- [ZJOI2006]物流运输 题解
[ZJOI2006]物流运输 时间限制: 10 Sec 内存限制: 162 MB 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个 ...
- BZOJ 1003[ZJOI2006]物流运输(SPFA+DP)
Problem 1003. -- [ZJOI2006]物流运输 1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: ...
- [ZJOI2006]物流运输(动态规划,最短路)
[ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个 ...
- [ZJOI2006]物流运输
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5999 Solved: 2473[Submit][Stat ...
- bzoj1003 [ZJOI2006]物流运输
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6300 Solved: 2597[Submit][Stat ...
随机推荐
- 报错: The type ByteInputStream is not accessible due to restriction on required library
报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...
- 浅谈python中的“ ==” 与“ is”、还有cmp
总之,比较内容相等使用 ‘==’ 1.is" 是用来比较 a 和 b 是不是指向同一个内存单元,而"=="是用来比较 a 和 b指向的内存单元中的值是不是相等 2.pyt ...
- eclipse中maven插件上传项目jar包到私服
我们知道,每一个公司都会有自己的工具包或公共包.这样的包就能够上传到公司的maven私服,就不用每一个人都去同步开发包了. 那么,怎么把本地项目打包并公布到私服呢?依照例如以下步骤就能够轻松完毕. 1 ...
- 盘点UML中的四种关系
生活中,我们既是独立的个体,又通过联系形成各种关系,比方说:朋友.恋人.父子,同学--于是乎,出现了神乎其神的六人定律. 那么在UML中又存在什么样的关系呢?以下我们来梳理一下. 关联(Associa ...
- Idea 13 新建maven项目
1.此时生成的maven项目没有web文件夹 file→New Project→Maven→Next→GID.AID (NewDemo)→Next→ProjectName(NewDemo)→Finis ...
- 网络知识: 物理层PHY 和 网络层MAC
PHY模块简介 物理层位于OSI最底层,物理层协议定义电气信号.线的状态.时钟要求.数据编码和数据传输用的连接器. 物理层的器件称为PHY. 上图里的灰色方框图里的就是PHY芯片内部模块图. MAC器 ...
- Repeater控件前台复杂逻辑判断
虽然现在开发大都是前后台ajax的方式,但是还有部分项目用后台cs代码+服务器控件开发的方式,小弟今天就遇到了一个 repeater显示列表,有一个字段是state状态,数据库里面存的是0 1 2类似 ...
- FFT做题记录
FFT是用来快速求卷积的..... 那么卷积有什么作用呢 https://www.zhihu.com/question/22298352 看完就懂了
- POJ1733 Parity game —— 种类并查集
题目链接:http://poj.org/problem?id=1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- add environment path to powershell
https://4sysops.com/archives/use-powershell-to-execute-an-exe/ https://stackoverflow.com/questions/7 ...