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)个 ... 
随机推荐
- switch滑动开关
			<!DOCTYPE html> <html> <head > <meta charset="utf-8"> <title> ... 
- ELK Betas 6.0安装及使用
			Betas 6.0安装及使用 注意: Elastic官网更新非常的快,每个版本的文档有会有不同,具体需要去官网查看最新文档进行配置调整. Beats 平台集合了多种单一用途数据采集器.这些采集器安装后 ... 
- libcurl移植到android
			一.总体概览 C库:libcurl 3.7 目标平台:android 编译平台:ubuntu 12 编译工具:ndk r7 or later 二.已知方法 1. 官网上给了两种方法,第一种方法是使用a ... 
- Oracl闪回数据命令。
			当数据库操作没有备份,并且误删数据.可闪回任何 当前闪回15分钟前数据库状态. alter table BASE_APPOINT_LOG enable row movement;flashback ... 
- 2-sat基础题  BZOJ 1823
			http://www.lydsy.com/JudgeOnline/problem.php?id=1823 1823: [JSOI2010]满汉全席 Time Limit: 10 Sec Memory ... 
- Why are Eight Bits Enough for Deep Neural Networks?
			Why are Eight Bits Enough for Deep Neural Networks? Deep learning is a very weird technology. It evo ... 
- Centos7系统环境下Solr之Java实战(二)制定中文分析器、配置业务域
			制定中文分析器 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下. 配置一个Fiel ... 
- python学习笔记(十六)之文件
			打开文件用open函数 open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=Tru ... 
- 【leetcode 简单】 第七题 合并两个有序链表
			将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1->2- ... 
- flex布局语法(阮一峰)
			Flex 布局教程:语法篇 作者: 阮一峰 日期: 2015年7月10日 网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + posi ... 
