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 ...
随机推荐
- html如何设置表格单元格内容垂直居中?
父元素设置为表格的单元格元素td,而在表格单元格中的元素设置vertical-align: middle; 对父容器(td)使用:display: table-cell 其内子元素使用:vertica ...
- stack和heap的区别
The difference between stack and heap memory allocation Posted: 11th August 2010 by Tim in C, C++, S ...
- java 的安装
下载 java的官方下载地址:https://www.java.com/zh_CN/ 安装 下载完成后,可以按照默认安装路径,也可以自行设置安装路径.例如我的安装路径为:D:\Program File ...
- spring boot自动配置之jdbc(转)
1.DataSource配置 1.1 默认配置application.xml spring.datasource.url=jdbc:mysql://localhost/test spring.data ...
- VUE.之安装 font-awesome
VUE.之安装 font-awesome 我们在项目中经常使用各种图标:font-awesome (http://fontawesome.dashgame.com/) 1.npm 安装font-awe ...
- 模板与泛型编程 c++ primer ch16.1
在摸板定义中,模板参数列表不能为空, 编译器用推断出的参数来进行 实例化(instantiation) 一般来说 模板是有type parameter 但是也可以声明 nontype paramete ...
- day36 05-Hibernate检索方式:离线条件查询
图二 离线条件查询 Struts 2是web层的框架.session得在dao层才有.有的时候这些数据是没在你的对象里面的.像是否上传简历.这个字段不在我的数据库里面.例如是否上传简历这个条件不在我们 ...
- idea添加jar包
之前一直使用eclipse,现在使用idea,发现两者引用外部jar的时候不太一样,分享一下. 使用eclipse引用外部jar的时候,我们可以在工程下新建一个lib包来存放,然后add to bui ...
- 组合数取模(lucas定理+CRT合并)(AC)
#include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inlin ...
- gb2312的6763个汉字
0a啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨安俺按暗岸胺案肮昂盎凹敖熬翱袄傲奥懊澳芭捌扒叭吧笆八疤巴拔跋靶把耙坝霸罢爸白柏百摆佰败拜稗斑班搬扳般颁板版扮拌伴瓣半办绊邦帮梆榜膀绑棒磅蚌镑傍谤苞胞包褒剥薄雹保堡 ...