Description

    农夫约翰正驾驶一条小艇在牛勒比海上航行.
    海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一
张藏宝图上说,如果他的路程上经过的小岛依次出现了 Ai,A2,…,AM(2≤M≤10000)这样的序列(不一定相邻),那他最终就能找到古老的宝藏.  但是,由于牛勒比海有海盗出没.约翰知道任意两 个岛屿之间的航线上海盗出没的概率,他用一个危险指数Dij(0≤Dij≤100000)来描述.他希望他的寻宝活动经过的航线危险指数之和最小.那么, 在找到宝藏的前提下,这个最小的危险指数是多少呢?

Input

    第1行输入N和M,之后M行一行一个整数表示A序列,之后输入一个NxN的方阵,表示两两岛屿之间航线的危险指数.数据保证Dij=Dji,Dii=0.

Output

 
    最小的危险指数和.

Sample Input

3 4
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

7

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

Silver

思路:最短路随便搞一下

 #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】的更多相关文章

  1. 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 ...

  2. BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路( 最短路 )

    直接floyd.. ----------------------------------------------------------------------- #include<cstdio ...

  3. BZOJ 1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路:floyd

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1624 题意: 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿, ...

  4. BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路

    Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上经过的小岛依次出 ...

  5. bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】

    弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...

  6. 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路

    1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 3 ...

  7. 【BZOJ】1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路(floyd)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1624 一开始我打算一个个最短路................................. 然 ...

  8. bzoj1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路

    Description     农夫约翰正驾驶一条小艇在牛勒比海上航行.     海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...

  9. [Usaco2008 Open] Clear And Present Danger 寻宝之路[最短路][水]

    Description     农夫约翰正驾驶一条小艇在牛勒比海上航行.     海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...

随机推荐

  1. cat 参数

    -A 相当于-vET的整合参数 -E 将结尾的换行符$显示出来 -n 显示行号 -T 将tab键以^T显示出来 -v 列出一些看不出来的特殊字符

  2. SQLServer同一实例下事务操作

    参考代码: 引用Dapper public bool OrderAdd2(User user, Order order) { string dbString = ConfigurationManage ...

  3. com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.168.1.13:20881, cause: Failed to bind to: /0.0.0.0:20881

    抛出的异常如上,解决方案是:根据异常信息确定是端口被占用,排查项目是否启动之后没有关闭,在windows命令行中运行如下命令:netstat -ano 检查端口占用的情况,根据pid在任务管理器中杀死 ...

  4. 中国剩余定理&Lucas定理&按位与——hdu 5446

    链接: hdu 5446 http://acm.hdu.edu.cn/showproblem.php?pid=5446 题意: 给你三个数$n, m, k$ 第二行是$k$个数,$p_1,p_2,p_ ...

  5. 为什么JS是单线程?JS中的Event Loop(事件循环)?JS如何实现异步?setimeout?

    https://segmentfault.com/a/1190000012806637 https://www.jianshu.com/p/93d756db8c81 首先,请牢记2点: (1) JS是 ...

  6. MAC 安装汇编编译工具 NASM

    直接运行nasm报错: 开始安装: brew reinstall nasm

  7. layui 数据table隐藏表头

    $('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式 /*$('th').css({' ...

  8. C++类型强制转换<转>

    转载:http://www.cnblogs.com/goodhacker/archive/2011/07/20/2111996.html C风格的强制类型转换(Type Cast)很简单,不管什么类型 ...

  9. Catalan 数

    概要 在一些面试的智力题中会遇到此数的变形,如果完全不了解,直接想结果是很困难的,故在此简单介绍一下.   基本定义 Catalan 数的定义根据不同的应用环境有很多不同的定义方式,下面给出一个.   ...

  10. OpenCV2:第八章 界面事件

    一.简介 OpenCV中提供了程序界面中的鼠标和键盘事件 二.鼠标事件 //  设置鼠标回调函数 void setMouseCallback ( const string& winname, ...