bfac3402-1150-46c7-8798-f545389dbac3
其使用最简单的方法做就好了忘了啥名字,类似于dp
给个代码

#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long c[105][105];
long long ans;
short l[100000];
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) cin >> l[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> c[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
c[j][k] = min(c[j][k],c[j][i] + c[i][k]);
}
}
}
for(int i = 2; i <= m; i++) {
ans += c[l[i - 1]][l[i]];
}
cout << ans << endl;
return 0;
}
/*
3 4
1
2
1
3
0 5 1
5 0 2
1 2 0 7
*/

注意:是for这样的

~~~~~~~~~~~~~

【重要】

------中转点
----------第一个点
--------------第二个点
再给个模板

for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
c[j][k] = min(c[j][k],c[j][i] + c[i][k]);
}
}
}

最新文章

  1. 没听说过这些,就不要说你懂并发了,three。
  2. ModelAndView详解
  3. 开始使用 Fresco
  4. Linux常用到的指令汇总
  5. javascript变量 数组 对象
  6. Python thread local
  7. 在CentOS 7中安装Redis 3.2.8
  8. Struts配置的各种视图转发类型
  9. ITU-T Technical Paper: QoS的构建模块与机制
  10. [Swift]LeetCode756. 金字塔转换矩阵 | Pyramid Transition Matrix
  11. python基础之Day18
  12. 史上最坑 idea 更改代码不生效
  13. php,mysql存储过程的简单例子
  14. e的故事.一个常数的传奇 (Eli Maor 著)
  15. nodejs使用案例-mysql操作
  16. mui-图文列表 图片大小问题
  17. SSI(Server Side Include)简单介绍
  18. 【Unity Shader】三、漫反射Diffuse Shader例子
  19. 30_AQS
  20. iOS 修改APP工程名字

热门文章

  1. java中json字符串与实体类对象相互转换
  2. Redis RDB 与AOF
  3. JDBC中文乱码问题
  4. JAVA中使用最广泛的本地缓存?Ehcache的自信从何而来 —— 感受来自Ehcache的强大实力
  5. C#应用程序配置文件(XML序列化) - 开源研究系列文章
  6. Windows 平台计算 CPU 总利用率
  7. A. Greatest Convex【Codeforces Round #842 (Div. 2)】
  8. 为测试管理正名,华为云CodeArts TestPlan的守护之道
  9. 刺激,线程池的一个BUG直接把CPU干到100%了。
  10. 构建api gateway之 http路由实现