[图论训练]BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【floyd】
Description
Input
Output
Sample Input
1
2
1
3
0 5 1
5 0 2
1 2 0
INPUT DETAILS:
There are 3 islands and the treasure map requires Farmer John to
visit a sequence of 4 islands in order: island 1, island 2, island
1 again, and finally island 3. The danger ratings of the paths are
given: the paths (1, 2); (2, 3); (3, 1) and the reverse paths have
danger ratings of 5, 2, and 1, respectively.
Sample Output
OUTPUT DETAILS:
He can get the treasure with a total danger of 7 by traveling in
the sequence of islands 1, 3, 2, 3, 1, and 3. The cow map's requirement
(1, 2, 1, and 3) is satisfied by this route. We avoid the path
between islands 1 and 2 because it has a large danger rating.
HINT
Source
思路:最短路随便搞一下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
//#include <map>
#include <queue>
#define maxn 100009
using namespace std;
int a[maxn],map[][];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++)scanf("%d",&a[i]);
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
scanf("%d",&map[i][j]);
}
}
for(int k = ; k <= n; k++)
{
for(int i = ; i <= n; i++)if(i != k)
{
for(int j = ; j <= n; j++)if(j != i && j != k)
{
map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
}
}
}
int ans = map[][a[]] + map[a[m]][n];
for(int i = ; i < m; i++)
{
ans += map[a[i]][a[i+]];
}
printf("%d\n",ans);
return ;
}
[图论训练]BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【floyd】的更多相关文章
- Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路( 最短路 )
直接floyd.. ----------------------------------------------------------------------- #include<cstdio ...
- BZOJ 1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路:floyd
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1624 题意: 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿, ...
- BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上经过的小岛依次出 ...
- bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】
弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...
- 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 3 ...
- 【BZOJ】1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=1624 一开始我打算一个个最短路................................. 然 ...
- bzoj1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
- [Usaco2008 Open] Clear And Present Danger 寻宝之路[最短路][水]
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
随机推荐
- apache安装报错
libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending /some_directory ...
- IOS弹出视图preferredContentSize
UIViewController.preferredContentSize代理旧方法 contentSizeForViewInPopover. self.contentSizeForViewInPop ...
- CocoaPods 安装使用
CocoaPods是一个负责管理iOS项目中第三方开源代码的工具.CocoaPods项目的源码在Github上管理.该项目开始于2011年8月 12日,经过一年多的发展,现在已经超过1000次提交,并 ...
- SC || 关于java迭代中修改迭代集合的操作
在通过for循环遍历整个List/Map等的时候,如果想要进行remove的操作,这时就更改了迭代集合,会出现错误 一种方法是如果只会remove一个可以remove后直接break 另一种是把集合先 ...
- [BZOJ4899]:记忆的轮廓(概率DP)
题目传送门 题目描述: 通往贤者之塔的路上,有许多的危机. 我们可以把这个地形看做是一颗树,根节点编号为1,目标节点编号为n,其中1-n的简单路径上,编号依次递增, 在[1,n]中,一共有n个节点.我 ...
- (1)JSTL的13个core标签库
标准标签库JSTL的全名为:Java Server Pages Standard Tag Library. (jsp standard tag library) JSTL主要提供了5大类标签库: ...
- javase(3)_二叉树
// 1.求二叉树中的节点个数 // 2.求二叉树的深度 // 3.前序遍历,中序遍历,后序遍历 // 4.分层遍历二叉树(按层次从上往下,从左往右) // 5.将二叉查找树变为有序的双向链表 // ...
- str.format输出乱码
如该示例,str.Format(L"相似度:%f\t视频名称:%s\t起始位置:%d\r\n",tmp[0].dblSimilarity,tmp[0].szFileName,tmp ...
- 如何优化sql查询
借鉴https://www.cnblogs.com/ssrstm/p/5753068.html和https://www.cnblogs.com/exe19/p/5786806.html 1. 对查询进 ...
- MySql中引擎
1. InnoDB 引擎 MySQL 5.5 及以后版本中的默认存储引擎,它的优点如下:灾难恢复性好,支持事务,使用行级锁,支持外键关联,支持热备份. InnoDB引擎中的表,其数据的物理组织形式是簇 ...