题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1624

题意:

  农夫约翰正驾驶一条小艇在牛勒比海上航行。

  海上有N(1≤N≤100)个岛屿,用1到N编号。

  约翰从1号小岛出发,最后到达N号小岛。

  一张藏宝图上说,如果他的路程上经过的小岛依次出现了Ai,A2,…,AM(2≤M≤10000)这样的序列(不一定相邻),那他最终就能找到古老的宝藏。

  但是,由于牛勒比海有海盗出没.约翰知道任意两个岛屿之间的航线上海盗出没的概率,他用一个危险指数Dij(0≤Dij≤100000)来描述。

  他希望他的寻宝活动经过的航线危险指数之和最小。

  那么,在找到宝藏的前提下,这个最小的危险指数是多少呢?

题解:

  floyd.

  然后求从1到a[1]、a[1]到a[2]...a[m]到n的dis之和。

AC Code:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_N 105
#define MAX_M 10005 using namespace std; int n,m;
int ans=;
int a[MAX_M];
int dis[MAX_N][MAX_N]; void read()
{
cin>>n>>m;
a[]=;
a[m+]=n;
for(int i=;i<=m;i++)
{
cin>>a[i];
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
cin>>dis[i][j];
}
}
} void floyd()
{
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i!=j && j!=k && i!=k)
{
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
}
} void solve()
{
floyd();
for(int i=;i<=m;i++)
{
ans+=dis[a[i]][a[i+]];
}
} void print()
{
cout<<ans<<endl;
} int main()
{
read();
solve();
print();
}

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】

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

  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. 四个很好的开源app项目

    Open Source and the iOS App Store Today, we are open-sourcing 4 iOS apps: ThatInbox, an email client ...

  2. 移除array中重复的item

    //move the repeated item            NSInteger index = [orignalArray count] - 1;            for (id o ...

  3. ios7.1后setting中没有开启相机服务应用程序相机预览黑屏问题

    if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){                               ...

  4. docker run 报错——WARNING: IPv4 forwarding is disabled. Networking will not work.

    执行  docker run  时遇到如下WARNING: [root@etcd1 volumes]# docker run -d -p 8080:80 -v /tmp/test_mount http ...

  5. npm、yarn、pnpm

    它们都是当前主流的包管理工具 pnpm:https://github.com/pnpm/pnpm yarn: https://github.com/yarnpkg/yarn npm: https:// ...

  6. project管理之makefile与自己主动创建makefile文件过程

    (风雪之隅 http://www.laruence.com/2009/11/18/1154.html) Linux Makefile自己主动编译和链接使用的环境 想知道到Linux Makefile系 ...

  7. android页面间传递对象

    android传递对象有两种方式: 一种是Serializable和Parcelable 对于第一种方式: import java.io.Serializable; public class Shop ...

  8. EC知识总结ITE5570

    以笔记本上的EC ITE5570进行讲解  ITE EC代码解析 1.一简介 EC(Embed Controller,嵌入式控制器)是一个16位单片机,它内部本身也有一定容量的Flash来存储EC的代 ...

  9. LINUXFOUNDATION EVENTS

    http://events.linuxfoundation.org/ #lflks This invitation-only event focuses on development and inno ...

  10. 轻松搞定RabbitMQ(一)——RabbitMQ基础知识+HelloWorld

    转自 http://blog.csdn.net/xiaoxian8023/article/details/48679609 本文是简单介绍一下RabbitMQ,参考官网上的教程.同时加入了一些自己的理 ...