P2910 [USACO08OPEN]Clear And Present Danger S题解
2024-10-21 13:37:24
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]);
}
}
}
最新文章
- 没听说过这些,就不要说你懂并发了,three。
- ModelAndView详解
- 开始使用 Fresco
- Linux常用到的指令汇总
- javascript变量 数组 对象
- Python thread local
- 在CentOS 7中安装Redis 3.2.8
- Struts配置的各种视图转发类型
- ITU-T Technical Paper: QoS的构建模块与机制
- [Swift]LeetCode756. 金字塔转换矩阵 | Pyramid Transition Matrix
- python基础之Day18
- 史上最坑 idea 更改代码不生效
- php,mysql存储过程的简单例子
- e的故事.一个常数的传奇 (Eli Maor 著)
- nodejs使用案例-mysql操作
- mui-图文列表 图片大小问题
- SSI(Server Side Include)简单介绍
- 【Unity Shader】三、漫反射Diffuse Shader例子
- 30_AQS
- iOS 修改APP工程名字
热门文章
- java中json字符串与实体类对象相互转换
- Redis RDB 与AOF
- JDBC中文乱码问题
- JAVA中使用最广泛的本地缓存?Ehcache的自信从何而来 —— 感受来自Ehcache的强大实力
- C#应用程序配置文件(XML序列化) - 开源研究系列文章
- Windows 平台计算 CPU 总利用率
- A. Greatest Convex【Codeforces Round #842 (Div. 2)】
- 为测试管理正名,华为云CodeArts TestPlan的守护之道
- 刺激,线程池的一个BUG直接把CPU干到100%了。
- 构建api gateway之 http路由实现