就我一开始写状压的吗?

调不过

后来发现(直接搜索)直接最短路就行了……

\(f[i]\)表示前\(i\)天最少需要多少

\(f[i] = min(f[j] + dis(j + 1, i))\)

然后就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> const int MAXN = 110;
const int MAXM = 22;
const int INF = 0x3f3f3f3f;
template<typename T>
inline void getmin(T & x, const T y) { if (x > y) x = y; }
int n, m, K, E, map[MAXM][MAXM];
int t1, t2, t3, cant[MAXN][MAXM], P, f[MAXN];
bool inq[MAXN], cnt[MAXM];
std::queue<int> q;
int dis[MAXM];
int bellman_ford(int b, int e) {
memset(cnt, 0, sizeof cnt);
for (int i = b; i <= e; ++i)
for (int j = 1; j <= m; ++j)
cnt[j] |= cant[i][j];
memset(dis, 0x3f, sizeof dis);
dis[1] = 0; q.push(1); inq[1] = true;
while (!q.empty()) {
int t = q.front(); q.pop(); inq[t] = false;
for (int i = 1; i <= m; ++i) if (!cnt[i])
if (dis[i] > dis[t] + map[t][i]) {
dis[i] = dis[t] + map[t][i];
if (!inq[i]) {
inq[i] = true;
q.push(i);
}
}
}
return dis[m];
}
int main() {
memset(map, 0x3f, sizeof map);
memset(f, 0x3f, sizeof f); f[0] = 0;
scanf("%d%d%d%d", &n, &m, &K, &E);
for (int i = 1; i <= E; ++i) {
scanf("%d%d%d", &t1, &t2, &t3);
getmin(map[t1][t2], t3);
getmin(map[t2][t1], t3);
}
scanf("%d", &P);
while (P --> 0) {
scanf("%d%d%d", &t1, &t2, &t3);
for (int i = t2; i <= t3; ++i)
cant[i][t1] = true;
}
for (int i = 1; i <= n; ++i)
for (int j = 0, t; j != i; ++j)
if ((t = bellman_ford(j + 1, i)) != INF)
getmin(f[i], f[j] + t * (i - j) + K * (j != 0));
printf("%d\n", f[n]);
return 0;
}

1003: [ZJOI2006]物流运输的更多相关文章

  1. BZOJ 1003 [ZJOI2006]物流运输trans

    1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4242  Solved: 1765[Submit] ...

  2. BZOJ 1003: [ZJOI2006]物流运输trans(最短路+dp)

    1A,爽! cost[i][j]表示从第i天到第j天不改路线所需的最小花费,这个可以用最短路预处理出.然后dp(i)=cost[j][i]+dp(j-1)+c. c为该路线的花费. --------- ...

  3. BZOJ(1) 1003 [ZJOI2006]物流运输

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 9404  Solved: 4087[Submit][Stat ...

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

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

  5. bzoj 1003 [ZJOI2006]物流运输(最短路+dp)

    [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 8973  Solved: 3839[Submit][Status][Di ...

  6. 【BZOJ】1003: [ZJOI2006]物流运输trans(SPFA+DP)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1003 这题一开始看是不会的额,,,还是看题解了..一开始我觉得不能用最短路啥的,,看了题解发现这是d ...

  7. 【BZOJ1003】1003: [ZJOI2006]物流运输trans SPFA+DP

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

  8. BZOJ 1003: [ZJOI2006]物流运输trans DP+最短路

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

  9. 1003. [ZJOI2006]物流运输【区间DP+最短路】

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

  10. 【刷题】BZOJ 1003 [ZJOI2006]物流运输

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

随机推荐

  1. 关于一个查询的JAVA界面,希望对你有启发

    package work2; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; ...

  2. python基础_面向对象进阶

    @property装饰器 之前我们讨论过Python中属性和方法访问权限的问题,虽然我们不建议将属性设置为私有的,但是如果直接将属性暴露给外界也是有问题的,比如我们没有办法检查赋给属性的值是否有效.我 ...

  3. expect批量分发密钥对

    vim shell.exp #!/usr/bin/expect set timeout 10 set hostname [lindex $argv 0] set username [lindex $a ...

  4. 什么是 Serverless 应用引擎?优势有哪些?

    Serverless 应用引擎(Serverless App Engine,简称 SAE)是面向应用的 Serverless PaaS 平台,能够帮助 PaaS 层用户免运维 IaaS,按需使用,按量 ...

  5. Tomcat 设置80端口

    1:修改tomcat配置 vi /usr/local/tomcat/conf/server.xml 找到 Connector port="8080" protocol=" ...

  6. 关于获取jquery对象的长度

    /* 17:10 2019/8/6 @author zhangxingshuo jQuery:"write less, do more" homepage: https://jqu ...

  7. call,apply,bind的理解

    call,apply,bind均是用于改变this指向. 三者相似之处: 1:都是用于改变函数的this指向. 2:第一个参数都是this要指向的对象. 3:都可以通过后面的参数进行对方法的传参. l ...

  8. js特效背景--点线随着鼠标移动而改变

    https://blog.csdn.net/css33/article/details/89450852 https://www.cnblogs.com/qq597585136/p/7019755.h ...

  9. electron builder 打包多个第三方依赖的软件

    背景 在实际的开发过程中,我们最后打包生成的exe.会依赖一些第三方的软件,或者说是一些系统的环境,比如 .net framework vc++ 等,这些环境不能依赖客户的环境,所以最好的做法是在打包 ...

  10. WebAPI跨域问题处理

    1.按照https://dzone.com/articles/access-control-allow-origin-header-and-the-aspnet文章所述,在程序中配置允许跨域请求. 但 ...