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)个 ...
随机推荐
- jquery收集页面参数生成xml,用于与server做数据交互
本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. http://www.cnblogs.com/king-xg/p/6382603.html 通过jquery ...
- HDU 5145 分块 莫队
给定n个数,q个询问[l,r]区间,每次询问该区间的全排列多少种. 数值都是30000规模 首先考虑计算全排列,由于有同种元素存在,相当于每次在len=r-l+1长度的空格随意放入某种元素即$\bin ...
- 关于aspx.designer.cs的研究
.aspx文件..aspx.cs文件和.aspx.designer.cs的一些说明 .aspx文件:(页面)书写页面代码.存储的是页面design代码.只是放各个控件的代码,处理代码一般放在.cs文件 ...
- idea自动识别get set方法
- Java面试中常问的Spring方面问题(涵盖七大方向共55道题,含答案)
1.一般问题 1.1. 不同版本的 Spring Framework 有哪些主要功能? VersionFeatureSpring 2.5发布于 2007 年.这是第一个支持注解的版本.Spring 3 ...
- [整理] magento搬家
将原来网站文件中的var文件中的cache和session文件删除,将media中的缓存文件删除.然后将所有文件制作成一个压缩包,以减少文件体积,方便转移. 将压缩包转移到新的服务器域名指向的文件夹, ...
- C - K-inversions URAL - 1523 (dp + 线段树)
题目链接:https://cn.vjudge.net/contest/275079#problem/C 具体思路:我们可以分层的去建立,假设我们要找k层,我们可以先把满足1.2....k-1层的满足情 ...
- Anaconda3的安装和汉化
下载页面 : https://www.anaconda.com/download 直接下载(Windows) : Anaconda3-5.0.0-Windows-x86_64.exe | Anacon ...
- [转载]PM管理技巧
产品经理的沟通策略 2016年10月11日/分类: 文章 /编辑: Amy 产品经理处于沟通枢纽的位置,工作中需要跟各种岗位的人打交道,比如:领导.开发.运营.客户.用户.合作伙伴… 沟通能力是产 ...
- uboot makefile构建分析-续
前言 这篇博文是 uboot makefile构建分析的续篇,继续分析uboot构建u-boot.bin的过程 构建u-boot.bin过程分析 makefile一开始,就是确定链接脚本.在构建ubo ...