就我一开始写状压的吗?

调不过

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

\(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. 正则爬取某段子网站前20页段子(request库)

    首先还是谷歌浏览器抓包对该网站数据进行分析,结果如下: 该网站地址:http://www.budejie.com/text 该网站数据都是通过html页面进行展示,网站url默认为第一页,http:/ ...

  2. redis配置文档细节问题

    在window10环境下,redis的.conf配置文件在使用时,不可以有多余的空白符.比如为了对其在配置的前方添加两个空格. 这么做会导致redis-server使用这个配置文件的时候无法正常启动, ...

  3. Android Monkey测试入门<1>

    第一步:搭建环境:主要是安装和搭建java和sdk环境,说白了,对我们安卓开发来说,只要搭建好了Android开发环境,Monkey测试环境基本就是OK的了.可以参考:http://www.cnblo ...

  4. myBatis+Spring+SpringMVC框架面试题整理

    myBatis+Spring+SpringMVC框架面试题整理(一) 2018年09月06日 13:36:01 新新许愿树 阅读数 14034更多 分类专栏: SSM   版权声明:本文为博主原创文章 ...

  5. springboot(十七)-使用Docker部署springboot项目

    Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下. 首先构建一个简单的 Spring Boot 项目, ...

  6. java 关于数字取小数点后两位出现整数0没有的问题

    最近再项目中对取到的一系列带很长小数的数字,展现时要求去小数点后两位显示就可以了 开始我是以下写法: double  a =  0.1234455; DecimalFormat decimalForm ...

  7. python之json操作

    1.json.dumps()用于将dict类型的数据转成str 备注:文件路径前面加上 r 是为了避免转义 1 import json 2 3 dict = {'a': 'wo', 'b': 'zai ...

  8. 25个免费的jQuery/ JavaScript的图表和图形库

    1.  JS Charts Features Prepare your chart data in XML, JSON or JavaScript Array Create charts in dif ...

  9. mySql 的常用命令

    一.数据库操作 1.创建数据库 create database <数据库名>: -- 例如,创建test数据库,create database test; 2.查询所有的数据库 show ...

  10. java笔记web

    1,spring请求同,返回同一个界面 Dubbo消费者无法连接到生产者提供的服务?内网IP? https://blog.csdn.net/xlgen157387/article/details/52 ...