mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 23:38:47 +00:00
P1690 贪婪的Copy
R54008212
This commit is contained in:
parent
a5e85d9936
commit
8799a1ac97
37
Luogu/problem/P1690/P1690.cpp
Normal file
37
Luogu/problem/P1690/P1690.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, p, g[105][105], a[15], ans = 0x3f3f3f3f, sum;
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
cin >> g[i][j];
|
||||
}
|
||||
}
|
||||
for (int k = 1; k <= n; k++) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
cin >> p;
|
||||
for (int i = 1; i <= p; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
a[0] = 1;
|
||||
a[p + 1] = n;
|
||||
sort(a + 1, a + p + 1);
|
||||
do {
|
||||
sum = 0;
|
||||
for (int i = 0; i <= p; i++) {
|
||||
sum += g[a[i]][a[i + 1]];
|
||||
}
|
||||
ans = min(ans, sum);
|
||||
} while (next_permutation(a + 1, a + p + 1));
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user