[BZOJ1003][ZJOI2006]物流运输(最短路+DP)
来源:互联网 发布:淘宝哪家女装质量好 编辑:程序博客网 时间:2024/06/08 00:47
可以得到,如果时间在一个区间
其中据说有状压的做法。
代码:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;inline int read() { int res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-'); if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); return bo ? ~res + 1 : res;}const int N = 3e4 + 5, M = 605, INF = 0x3f3f3f3f;int n, m, K, E, q, ecnt, nxt[N], adj[N], go[N], dis[N], val[N], is[M][M],len, que[N], f[N];bool can[N], vis[N];void add_edge(int u, int v, int w) { nxt[++ecnt] = adj[u]; adj[u] = ecnt; go[ecnt] = v; val[ecnt] = w; nxt[++ecnt] = adj[v]; adj[v] = ecnt; go[ecnt] = u; val[ecnt] = w;}int spfa() { int i; for (i = 1; i <= m; i++) dis[i] = INF; dis[que[len = 1] = 1] = 0; for (i = 1; i <= len; i++) { int u = que[i]; vis[u] = 0; for (int e = adj[u], v; e; e = nxt[e]) if (can[v = go[e]] && dis[u] + val[e] < dis[v]) { dis[v] = dis[u] + val[e]; if (!vis[v]) vis[que[++len] = v] = 1; } } return dis[m];}int main() { int i, j, k, x, y, z; n = read(); m = read(); K = read(); E = read(); for (i = 1; i <= E; i++) x = read(), y = read(), z = read(), add_edge(x, y, z); q = read(); while (q--) { x = read(); y = read(); z = read(); is[x][y]++; is[x][z + 1]--; } for (i = 1; i <= m; i++) for (j = 2; j <= n; j++) is[i][j] += is[i][j - 1]; for (i = 1; i <= n; i++) { f[i] = INF; for (j = 1; j <= m; j++) can[j] = 1; for (j = i; j; j--) { for (k = 1; k <= m; k++) if (is[k][j]) can[k] = 0; int val = spfa(); if (val >= INF) continue; f[i] = min(f[i], f[j - 1] + val * (i - j + 1) + K * (j > 1)); } } cout << f[n] << endl; return 0;}
阅读全文
0 0
- [BZOJ1003]ZJOI2006 物流运输 |最短路|DP
- 【bzoj1003】【ZJOI2006】【物流运输】【dp+最短路】
- 【bzoj1003】【ZJOI2006】【物流运输】【最短路+dp】
- 【DP+最短路】BZOJ1003 [ZJOI2006]物流运输
- bzoj1003 [ZJOI2006]物流运输(最短路+dp)
- BZOJ1003(ZJOI2006)[物流运输]--最短路+DP
- [BZOJ1003][ZJOI2006]物流运输(最短路+dp)
- bzoj1003: [ZJOI2006]物流运输(最短路+Dp)
- [BZOJ1003][ZJOI2006]物流运输(最短路+dp)
- [BZOJ1003][ZJOI2006]物流运输(最短路+DP)
- 【BZOJ1003】物流运输(ZJOI2006)-DP+最短路
- bzoj1003: [ZJOI2006]物流运输trans[最短路+DP]
- 【bzoj1003】【最短路+DP】【ZJOI2006】物流运输trans
- 【bzoj1003】[ZJOI2006]物流运输trans 最短路+dp
- 【BZOJ1003】[ZJOI2006]物流运输trans【最短路】【DP】
- 最短路+DP——BZOJ1003/Luogu1772 [ZJOI2006]物流运输
- bzoj1003 [ZJOI2006]物流运输(spfa+dp)
- [DP] BZOJ1003: [ZJOI2006]物流运输
- LeeCode 495. Teemo Attacking
- 如何学好C++语言
- 汇编学习:函数调用过程中的堆栈分析
- c++:为什么模板不支持分离编译?
- 路由
- [BZOJ1003][ZJOI2006]物流运输(最短路+DP)
- hdu
- 巧妙的处理前端提交的空字符串(ID)
- 最大熵马尔可夫模型MEMM
- java集合中可变参数的使用
- 负载均衡实现原理
- 三个事和三个问题
- 第九章0.4
- Camel可视化操作(结合Gooflow)