bzoj1624 寻宝之路
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 tovisit a sequence of 4 islands in order: island 1, island 2, island1 again, and finally island 3. The danger ratings of the paths aregiven: the paths (1, 2); (2, 3); (3, 1) and the reverse paths havedanger ratings of 5, 2, and 1, respectively.
Sample Output
OUTPUT DETAILS:
He can get the treasure with a total danger of 7 by traveling inthe 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 pathbetween islands 1 and 2 because it has a large danger rating.
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=100+10,maxm=1e4+10;
int n,m,a[maxm];//
long long dis[maxn][maxn],ans; long long aa;char cc;
long long read() {
aa=0;cc=getchar();
while(cc<'0'||cc>'9') cc=getchar();
while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
return aa;
} int main() {
n=read();m=read();a[0]=1;
for(int i=1;i<=m;++i) a[i]=read();a[m+1]=n;
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) dis[i][j]=read();
for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
for(int i=0;i<=m;++i) ans+=dis[a[i]][a[i+1]];
cout<<ans;
return 0;
}
bzoj1624 寻宝之路的更多相关文章
- BZOJ_1624_ [Usaco2008_Open]_Clear_And_Present_Danger_寻宝之路_(最短路_Floyd)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1025 给出\(n\)个点以及之间的边的长度,给出必须访问的点的顺序,求最短路线长度. 分析 用 ...
- 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 ...
- 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 ...
- bzoj1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
- BZOJ 1624: [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号小岛.一 张藏宝图上说,如果他的路程上 ...
- Luogu [USACO08OPEN]寻宝之路Clear And Present Danger
题目描述 Farmer John is on a boat seeking fabled treasure on one of the N (1 <= N <= 100) islands ...
随机推荐
- netbeans 8.2 系统找不到指定的文件。
系统找不到指定的文件.Using CATALINA_BASE: "C:\Users\wishr\AppData\Roaming\NetBeans\8.2\apache-tomcat-8.0. ...
- CentOS 6 忘记root密码的修改方法
1.Linux的root密码修改不像Windows的密码修改找回,Windows的登录密码忘记需要介入工具进行解决.CentOS6和CentOS7的密码方法也是不一样的,具体如下: 2.centos ...
- 二、Web Service开发(.net)
.net平台内建了对Web Service的支持,包括Web Service的构建和使用.与其它开发平台不同,使用.net平台,你不需要其他的工具或者SDK就可以完成Web Service的开发了.. ...
- linux下用eclipse开发mapreduce遇到的问题
Unable to create the selected preference page.org/apache/hadoop/eclipse/preferences/MapReducePrefere ...
- Leetcode98. Validate Binary Search Tree验证二叉搜索树
给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也是二叉搜索 ...
- 【html、CSS、javascript-11】jquery-事件使用方法总结
jquery提供了许多的事件处理函数,下面对其总结一下,梳理一下知识点,便于记忆和使用. 一.鼠标事件 1. click():鼠标单击事件 $div = $("div") $div ...
- Django项目:CRM(客户关系管理系统)--29--21PerfectCRM实现King_admin查看页面美化
{#table_data_list.html#} {## ————————08PerfectCRM实现King_admin显示注册表的字段表头————————#} {% extends 'king_m ...
- 记一次PHP 数组基本用法
以前不知道PHP数组可以这样叠加. $b = array( '2' => 'zhang', ); $a = array( ' => 'li' ) + $b; print_r($a); $b ...
- 一探前端开发中的JS调试技巧(转)
有请提示:文中涉及较多Gif演示动画,移动端请尽量在Wifi环境中阅读 前言:调试技巧,在任何一项技术研发中都可谓是必不可少的技能.掌握各种调试技巧,必定能在工作中起到事半功倍的效果.譬如,快速定位问 ...
- 没有ORM库的时候,通过PDO连接MySQL的方法
$pdo = new PDO("mysql:host=localhost;dbname=eq","root","root"); $pdo-& ...