NBUT 1221 Intermediary
最短路,三进制状态压缩。
$dis[i][j]$表示到$i$节点,每个中介用了几次的情况下的最小花费,跑最短路即可。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<iostream>
using namespace std; int n,m,q;
int e[],f[],r[]; struct X
{
int a,b,z,d;
int nx;
}ee[]; struct Y
{
int id,st,dis;
Y(int ID,int ST,int DIS)
{
id=ID;
st=ST;
dis=DIS;
} bool operator <(const Y&y) const
{
return dis>y.dis;
}
}; int h[], dis[][];
int t[]; void dij()
{
for(int i=;i<n;i++)
for(int j=;j<t[m];j++)
dis[i][j]=0x7FFFFFFF; dis[][]=;
priority_queue<Y>Q; Q.push(Y(,,)); while(!Q.empty())
{
Y q = Q.top(); Q.pop();
if(q.dis>dis[q.id][q.st]) continue;
if(q.id==n-)
{
printf("%d\n",q.dis);
return ;
} for(int i=h[q.id];i!=-;i=ee[i].nx)
{
int tmp=q.st;
for(int j=;j<m;j++) r[j]=tmp%,tmp/=; int cost = ee[i].d, v = ;
if(r[ee[i].z]==) cost += e[ee[i].z];
else if(r[ee[i].z]==) cost += f[ee[i].z],v=; if(q.dis+cost<dis[ee[i].b][q.st+v*t[ee[i].z]])
{
dis[ee[i].b][q.st+v*t[ee[i].z]] = q.dis+cost;
Q.push(Y(ee[i].b,q.st+v*t[ee[i].z],dis[ee[i].b][q.st+v*t[ee[i].z]]));
}
}
}
} int main()
{
t[]=; for(int i=;i<=;i++) t[i]=*t[i-]; while(~scanf("%d%d%d",&n,&m,&q))
{
for(int i=;i<m;i++) scanf("%d",&e[i]);
for(int i=;i<m;i++) scanf("%d",&f[i]); memset(h,-,sizeof h); for(int i=;i<=q;i++)
{
scanf("%d%d%d%d",&ee[i].a,&ee[i].b,&ee[i].z,&ee[i].d);
ee[i].nx = h[ee[i].a];
h[ee[i].a]=i;
} dij();
}
return ;
}
NBUT 1221 Intermediary的更多相关文章
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- BZOJ 1221: [HNOI2001] 软件开发
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1428 Solved: 791[Submit][Stat ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
NBUT 1646 Internet of Lights and Switches Time Limit:5000MS Memory Limit:65535KB 64bit IO Fo ...
- ural 1221. Malevich Strikes Back!
1221. Malevich Strikes Back! Time limit: 1.0 secondMemory limit: 64 MB After the greatest success of ...
- 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1221 先吐槽一下,数组依旧开小了RE:在spfa中用了memset和<queue>的版本 ...
- NBUT 1525 Cow Xor(01字典树+前缀思想)
[1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...
随机推荐
- zlib解压缩gzip
zlib是个著名的开源解压缩库,gzip是一种压缩文件格式. zlib可以压缩原始数据并输出gzip文件,gzip文件中除了压缩数据外,还有描述这些数据的文件头,所以当原始数据较小时,会出现zlib的 ...
- Ubuntu+NDK编译支持HTTPS的libcurl
参考文章:1.NDK环境配置 http://blog.csdn.net/smfwuxiao/article/details/65877092.libcurl的配置修改 http://piggyq.co ...
- Linux Shell 程序调试
Linux Shell 程序调试 Shell程序的调试是通过运行程序时加入相关调试选项或在脚本程序中加入相关语句,让shell程序在执行过程中显示出一些可供参考的“调试信息”.当然,用户也可以在she ...
- MYSQL5.6学习——mysqldump备份与恢复
MYSQL备份 冷备份:停止服务进行备份,即停止数据库的写入 热备份:不停止服务进行备份(在线) l mysql的MyIsam引擎只支持冷备份,InnoDB支持热备份,原因: InnoDB引擎是事务 ...
- asp.net core 实践
github:https://github.com/zzhi/DotNetWeb 这是一个基于asp.net core web application的练习项目,目的是学习dotnet core新技能 ...
- GridControl详解(六)样式设置
表格样式:全局设置 例子: 例子: 列样式:只作用于当前的列 通用样式:外观设定 注意:样式设定都是相同的,Appearance前缀.
- GridControl详解(一)原汁原味的表格展示
Dev控件中的表格控件GridControl控件非常强大.不过,一些细枝末节的地方有时候用起来不好找挺讨厌的.使用过程中,多半借助Demo和英文帮助文档.网上具体的使用方法也多半零碎.偶遇一个简单而且 ...
- HNOI2019退役祭
对你没看错,是退役祭. Day -2 春游.话说为什么又是植物园? Day -1 白天上文化课,晚上给机房其它童鞋出题. Day 0 给他们考试,然后颓3Dmaze,毕竟没网 Day 1 车上复习了下 ...
- 【洛谷 P4219】 [BJOI2014]大融合(LCT)
题目链接 维护子树信息向来不是\(LCT\)所擅长的,所以我没搞懂qwq 权当背背模板吧.Flash巨佬的blog里面写了虽然我没看懂. #include <cstdio> #define ...
- NYOJ 1012 RMQ with Shifts (线段树)
题目链接 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each q ...