luogu 1772 物流运输 ZJOI2006 spfa+dp
主要路径上存在时间限制(消失)
因为数据较小(点数较小),利用限制条件在规定时间内分别spfa,(也可用floyd)
再通过dp取最优值
#include<bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(register int i=x;i<=y;i++)
using namespace std;
inline int read(){
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
return x*f;}
const int N=;
const int M=;
const int T=;
const int inf=0x3f3f3f3f; int day,n,rec,m,d,t,dis[N];
int close[N][T],now[N],vis[N];
ll cost[T][T],f[T]; int head[N],tot;
struct node{int v,w,next;}e[M];
void insert(int u,int v,int w){
e[++tot]=(node){v,w,head[u]};head[u]=tot;
e[++tot]=(node){u,w,head[v]};head[v]=tot;} int spfa(int x,int y){
memset(dis,inf,sizeof dis);
memset(vis,,sizeof vis);
memset(now,,sizeof now); rep(i,,n)rep(j,x,y)
if(close[i][j]) now[i]=; queue<int> q;
q.push();dis[]=;vis[]=;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=;
for(int i=head[u];i;i=e[i].next){
int v=e[i].v,w=e[i].w;
if(now[v]) continue;
if(dis[u]+w<dis[v]){
dis[v]=dis[u]+w;
if(!vis[v]) vis[v]=,q.push(v);
}
}
}return dis[n];
}
int main(){
day=read(),n=read(),rec=read(),m=read();
rep(i,,m){
int u=read(),v=read(),w=read();insert(u,v,w);}
t=read();
rep(i,,t){
int p=read(),u=read(),v=read();
rep(j,u,v) close[p][j]=;}
rep(i,,day)rep(j,,day)
cost[i][j]=spfa(i,j);
rep(i,,day){
f[i]=(ll)cost[][i]*i;
rep(j,,i)
f[i]=min(f[i],f[j]+(ll)cost[j+][i]*(i-j)+rec);}
printf("%lld\n",f[day]); return ;
}
luogu 1772 物流运输 ZJOI2006 spfa+dp的更多相关文章
- 【BZOJ1003】1003: [ZJOI2006]物流运输trans SPFA+DP
Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...
- BZOJ 1003 [ZJOI2006]物流运输trans SPFA+DP
题意:链接 方法:SPFA+DP 解析:挺好的题目.因为数据范围较小所以用这样的方式能够搞,只是也是挺不好想的. 我们定义cost(i,j)表示从第i天走到第j天运用同一种方式的最小花费,然后因为数据 ...
- BZOJ-1003 物流运输trans SPFA+DP
傻逼错误耗我1h,没给全范围坑我1A.... 1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MB Submit: 529 ...
- BZOJ 1003: [ZJOI2006]物流运输(spfa+dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1003 题意: 思路: 首先用spfa计算一下任意两天之内的最短路,dis[a][b]表示的就是在第a ...
- bzoj 1003: [ZJOI2006]物流运输【spfa+dp】
预处理出ans[i][j]为i到j时间的最短路,设f[i]为到i时间的最小代价,转移显然就是 f[i]=min(f[j-1]+ans[j][i]*(i-j+1)+k); #include<ios ...
- BZOJ1003 物流运输 最短路+DP
1003: [ZJOI2006]物流运输 Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条 ...
- BZOJ 1003 物流运输 (动态规划 SPFA 最短路)
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5590 Solved: 2293 [Submit][Stat ...
- BZOJ 1003 物流运输trans dijstra+dp
1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3896 Solved: 1608[Submit] ...
- bzoj1003物流运输 最短路+DP
bzoj1003物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输 ...
随机推荐
- 使用item pipeline处理保存数据
一个Item Pipeline 不需要继承特定基类,只需要实现某些特定方法,面向接口. class MyPipeline(object): def __init__(self): "&quo ...
- codeforces #530 D(Sum in the tree) (树上贪心)
Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each ve ...
- Linux服务器SSH免密互访
1.编辑Hosts文件: [root@yqtrack-elk01 /]# vim /etc/hosts
- A1124. Raffle for Weibo Followers
John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers ...
- [nowcoderACM_223C][区区区间间间]
题目链接 思路 考虑用单调栈,栈顶为最大元素.当得到一个新值得时候,将这个值宇栈顶比较.因为栈顶是前面的最大元素.所以只要当前元素比栈顶大,那么肯定比前面的都大.只要将这个元素乘上前面的个数就行了. ...
- Mysql 远程连接服务器
#授权外部访问 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; #清空mysql缓存 ...
- postman 抓包工具charles的使用
1.直接打开charles,然后,如果有https的话,需要安装证书,然后,设置代理 2.如果不是https的,不需要设置代理,直接抓取就可以 先安装证书: 然后设置代理: ...
- POJ 1659 Frogs' Neighborhood (Havel--Hakimi定理)
Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 10545 Accepted: 4 ...
- Linux 上 nginx配置
1:安装工具包 wget.vim和gcc yum install -y wget yum install -y vim-enhanced yum install -y make cmake gcc g ...
- node(基础)_node.js中的http服务以及模板引擎的渲染
一.前言 本节的内容主要涉及: 1.node.js中http服务 2.node.js中fs服务 3.node.js中模板引擎的渲染 4.利用上面几点模拟apache服务器 二.知识 1.node.js ...