[图论训练]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号小岛.一 张藏宝图上说,如果他的路程上 ...
随机推荐
- [windows]win7设置wifi热点
1.启用并设定虚拟WiFi网卡:netsh wlan set hostednetwork mode=allow ssid=whylaughing key=124025621 2.开启无线wifi网络: ...
- iOS图片目录批量复制到android图片目录
复制shell脚本 #!/bin/bash for i in `ls` do for imgname in `ls $i | grep '^WM.*'` do echo $imgname cp $i/ ...
- Luogu P4463 [国家集训队] calc
WJMZBMR的题果然放在几年后看来仍然挺神,提出了一种独特的优化DP的方式 首先我们想一个暴力DP,先定下所有数的顺序(比如强制它递增),然后最后乘上\(n!\)种排列方式就是答案了 那么我们容易想 ...
- WPF知识点全攻略08- 依赖属性
依赖属性是WPF不得不提,不得不会系列又一 先来看一下,自定义依赖属性的写法 public static readonly DependencyProperty IconProperty = Depe ...
- 服务器配置iis,php网站
1.在iis中选择物理路径.配置域名 2.添加php默认文档 3.修改处理程序映射 4.设置模块映射信息
- shell脚本,一个shell的启动流程。
#一个shell的启动流程 #shell有一些变量,叫做环境变量,这些变量是可以继承的, #比如父shell有$UID,子shell也可以有,而且继承父shell的. #正常我们声明一个变量,a=,在 ...
- PHP必知必会
MQ(消息队列) 消息队列主要用于以下场景: 1. 上传图片,用户需要迅速反馈,把上传图片的后续操作交给consumer 2. A用户对B用户发消息 3. 日志记录,APP发生的任何警告错误日志都要被 ...
- static静态变量的用法
一,static全局变量 当一个进程的全局变量被声明为static之后,它的中文名叫静态全局变量.静态全局变量和其他的全局变量的存储地点并没有区别,都是在.data段(已初始化)或者.bss段(未初始 ...
- 永久激活IDEA的方法
第一步,下载破解补丁jetbrains-agent.jar 链接:https://pan.baidu.com/s/15x6dzOjveMkHlgHJT0PBWg提取码:2ykx 第二步,将下载的破解补 ...
- perl学习之HERE文档
Perl的here文档机制是从UNIX shell中的here文档机制派生而来的. 和在shell中一样,Perl中的here文档也是面向行的引用表单,要求提供<<运算符,其后跟随一个初始 ...