BZOJ_1624_ [Usaco2008_Open]_Clear_And_Present_Danger_寻宝之路_(最短路_Floyd)
描述
http://www.lydsy.com/JudgeOnline/problem.php?id=1025
给出\(n\)个点以及之间的边的长度,给出必须访问的点的顺序,求最短路线长度.
分析
用Floyd求多源最短路,然后加起来就好了.
#include <bits/stdc++.h>
using namespace std; const int maxn=+,maxm=+;
int n,m,ans;
int a[maxm];
int d[maxn][maxn];
inline int read(int &x){x=;int k=;char c;for(c=getchar();c<''||c>'';c=getchar())if(c=='-')k=-;for(;c>=''&&c<='';c=getchar())x=x*+c-'';return x*=k;}
int main(){
read(n); read(m);
for(int i=;i<=m;i++) read(a[i]);
for(int i=;i<=n;i++)for(int j=;j<=n;j++) read(d[i][j]);
for(int k=;k<=n;k++)for(int i=;i<=n;i++)for(int j=;j<=n;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
for(int i=;i<m;i++) ans+=d[a[i]][a[i+]];
printf("%d\n",ans);
return ;
}
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 570 Solved: 379
[Submit][Status][Discuss]
Description
Ai,A2,…,AM(2≤M≤10000)这样的序列(不一定相邻),那他最终就能找到古老的宝藏. 但是,由于牛勒比海有海盗出没.约翰知道任意两
个岛屿之间的航线上海盗出没的概率,他用一个危险指数Dij(0≤Dij≤100000)来描述.他希望他的寻宝活动经过的航线危险指数之和最小.那么,
在找到宝藏的前提下,这个最小的危险指数是多少呢?
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
BZOJ_1624_ [Usaco2008_Open]_Clear_And_Present_Danger_寻宝之路_(最短路_Floyd)的更多相关文章
- 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 3 ...
- 洛谷——P2910 [USACO08OPEN]寻宝之路Clear And Present Danger
P2910 [USACO08OPEN]寻宝之路Clear And Present Danger 题目描述 Farmer John is on a boat seeking fabled treasur ...
- 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_4016_[FJOI2014]最短路径树问题_最短路+点分治
BZOJ_4016_[FJOI2014]最短路径树问题_最短路+点分治 Description 给一个包含n个点,m条边的无向连通图.从顶点1出发,往其余所有点分别走一次并返回. 往某一个点走时,选择 ...
- BZOJ_2622_[2012国家集训队测试]深入虎穴_最短路
BZOJ_2622_[2012国家集训队测试]深入虎穴_最短路 Description 虎是中国传统文化中一个独特的意象.我们既会把老虎的形象用到喜庆的节日装饰画上,也可能把它视作一种邪恶的可怕的动物 ...
- BZOJ_1003_[ZJOI2006]物流运输_最短路+dp
BZOJ_1003_[ZJOI2006]物流运输_最短路+dp 题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1003 分析: 这种一段一段的显 ...
- BZOJ_2118_墨墨的等式_最短路
BZOJ_2118_墨墨的等式_最短路 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及 ...
- 屠龙之路_任生活如何虐你,屠龙之路还得继续_SeventhDay
摘要 :屠龙少年在"罢工"了一天,在周末客栈补给和放纵之后,突然想起来说好的和公主私奔呢?(此处出现了为何上篇随笔不见公主)咋想之下,貌似公主还在恶龙Alpha的手中.为此,屠龙少 ...
随机推荐
- 《C++Primer》复习——with C++11 [2]
1.数组引用形参,C++允许将变量定义成数组的引用,给予同样的道理,形参也可以是数组的引用,此时引用形参绑定到对应的实参上,也就是绑定到数组上 ]) { for (auto elem : arr) c ...
- ContextLoaderListener作用详解
参考网址:http://blog.csdn.net/ysughw/article/details/8992322 ContextLoaderListener监听器的作用就是启动Web容器时,自动装配A ...
- Asp.Net修改上传文件大小限制(修改web.config)
i. Configuration节点下 <system.webServer> <security> <requestFiltering> <!--单位为字节 ...
- DevExpress控件使用系列--ASPxGridView+Popup+Tab
1.控件功能 列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例 2.1 ASPxGridView http ...
- epoll 知识总结
poll/select/epoll 对比 http://www.cnblogs.com/apprentice89/p/3234677.html ---有待继续学习 http://blog.chi ...
- php浮点数精确运算
php浮点数精确运算 Php: BCMath bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(strin ...
- C#三种定时器的实现
http://www.coridc.com/archives/2253.html c#中提供了三种类型的计时器: 1.基于 Windows 的标准计时器(System.Windows.Forms.Ti ...
- 读写txt文件
public void SetUpdateTime(string strNewDate) { try { var path =Application.StartupPath + Configurati ...
- hdu2010
//很闲,刷水..... http://acm.hdu.edu.cn/showproblem.php?pid=2010 #include<iostream> #include<std ...
- Linux shell 脚本小记
if结构 #!/bin/env bash -gt ] then echo "$1 is positive" -lt ] then echo "$1 is negative ...