博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线
阅读量:7197 次
发布时间:2019-06-29

本文共 1868 字,大约阅读时间需要 6 分钟。

 

这也算分层图最短路?

dp[i][j]到城市i,还剩k次免费次数的最短路

 

#include
#include
#include
#include
#include
using namespace std;#define N 10001#define M 50001int n,k;int S,T;int tot;int front[N],nxt[M<<1],to[M<<1],val[M<<1];int dp[N][11];bool vis[N][11];struct node{ int pos,rest; int dis; node(int Pos=0,int Rest=0,int Dis=0):pos(Pos),rest(Rest),dis(Dis){} bool operator < (node p) const { return dis>p.dis; }}now;priority_queue
q;void read(int &x){ x=0; char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }}void add(int u,int v,int w){ to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w; to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=w;}void dijkstra(){ memset(dp,63,sizeof(dp)); dp[S][k]=0; now.pos=S; now.rest=k; q.push(now); int u,v,cnt; while(!q.empty()) { now=q.top(); q.pop(); u=now.pos; cnt=now.rest; if(vis[u][cnt]) continue; vis[u][cnt]=true; for(int i=front[u];i;i=nxt[i]) { v=to[i]; if(dp[u][cnt]+val[i]

 

2763: [JLOI2011]飞行路线

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 3831  Solved: 1460
[ ][ ][ ]

Description

Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司。该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价格。Alice和Bob现在要从一个城市沿着航线到达另一个城市,途中可以进行转机。航空公司对他们这次旅行也推出优惠,他们可以免费在最多k种航线上搭乘飞机。那么Alice和Bob这次出行最少花费多少?

Input

数据的第一行有三个整数,n,m,k,分别表示城市数,航线数和免费乘坐次数。
第二行有两个整数,s,t,分别表示他们出行的起点城市编号和终点城市编号。(0<=s,t<n)
接下来有m行,每行三个整数,a,b,c,表示存在一种航线,能从城市a到达城市b,或从城市b到达城市a,价格为c。(0<=a,b<n,a与b不相等,0<=c<=1000)
 

Output

 
只有一行,包含一个整数,为最少花费。

Sample Input

5 6 1
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100

Sample Output

8

HINT

 

对于30%的数据,2<=n<=50,1<=m<=300,k=0;

对于50%的数据,2<=n<=600,1<=m<=6000,0<=k<=1;

对于100%的数据,2<=n<=10000,1<=m<=50000,0<=k<=10.

 

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8420906.html

你可能感兴趣的文章
读书笔记—CLR via C#章节11-13
查看>>
poj 2154 Color——带优化的置换
查看>>
Yii 框架里数据库操作详解-[增加、查询、更新、删除的方法 'AR模式'](转)
查看>>
asp.net 服务器 上传文件到 FTP服务器
查看>>
ZooKeeper学习第一期---Zookeeper简单介绍
查看>>
Mybatis(spring)(多个参数)(插入数据返回id)
查看>>
操作系统学习笔记三 进程
查看>>
Map的嵌套使用
查看>>
实习公司的开发环境搭建教程
查看>>
Linux busybox mount -a fstab
查看>>
Dijkstra
查看>>
property测试代码:
查看>>
[C# | WinCE | Solution] 在 WinCE 上访问 SSL 加密后的 WCF SOAP 服务接口出现“未能与远程服务器建立信任关系”...
查看>>
css2D转换和3D转换
查看>>
synchronized关键字的用法总结
查看>>
用C实现一个简单的对拍器——致每个曾经为求AC披星戴月的程序员们
查看>>
C++的const类成员函数
查看>>
js 事件驱动机制
查看>>
进程相关内容
查看>>
框架,样式
查看>>