for the suggestions you give in the last chat, output the code.
时间: 2024-02-23 18:00:38 浏览: 73
Sure, here is the code with the suggested modifications:
```
#include <iostream>
#include <vector>
#define BIAS -1000
#define MY_INT_MIN -20000001
#define MY_INT_MAX 20000001
int main() {
int n, res = 0, tmp_pt = 0, last_pt = 0, tmp_val = MY_INT_MAX, last_val = 0, tmp_prt = 0;
std::vector<int> queue;
std::cin >> n;
const int N = n;
int mtrx[N][N], w[N], prt[N];
for (int i = 0; i < n; i++) {
std::cin >> w[i];
if (w[i] < tmp_val) {
tmp_val = w[i];
tmp_pt = i;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
std::cin >> mtrx[i][j];
if (i == j) {
mtrx[i][j] = MY_INT_MIN;
}
}
}
mtrx[tmp_pt][tmp_pt] = tmp_val;
for (int i = 0; i < n - 1; i++) {
last_pt = tmp_pt;
tmp_val = MY_INT_MAX;
for (int j = 0; j < n; j++) {
if (mtrx[j][last_pt] < (BIAS - mtrx[j][j])) {
mtrx[j][j] = BIAS - mtrx[j][last_pt];
prt[j] = ~last_pt;
if (mtrx[j][last_pt] < tmp_val) {
tmp_val = mtrx[j][last_pt];
tmp_pt = j;
}
}
else if (BIAS > mtrx[j][j] && mtrx[j][last_pt] < tmp_val) {
tmp_val = mtrx[j][last_pt];
tmp_pt = j;
}
}
mtrx[tmp_pt][tmp_pt] = ~prt[tmp_pt];
}
for (int i = 0; i < n - 1; i++) {
tmp_val = MY_INT_MAX;
for (int j = 0; j < n; j++) {
if (mtrx[j][j] < 0 && w[j] < tmp_val) {
tmp_val = w[j];
tmp_pt = j;
}
}
last_pt = tmp_pt;
last_val = tmp_val;
while (mtrx[tmp_pt][tmp_pt] < 0) {
tmp_prt = ~mtrx[tmp_pt][tmp_pt];
if (mtrx[tmp_pt][tmp_prt] > tmp_val) {
tmp_val = mtrx[tmp_pt][tmp_prt];
}
tmp_pt = tmp_prt;
}
if (last_val != tmp_val) {
queue.clear();
tmp_pt = last_pt;
while (mtrx[tmp_pt][tmp_pt] < 0) {
queue.push_back(tmp_pt);
tmp_prt = ~mtrx[tmp_pt][tmp_pt];
if (mtrx[tmp_pt][tmp_prt] == tmp_val) {
break;
}
tmp_pt = tmp_prt;
}
for (int j = queue.size() - 1; j > 0; j--) {
mtrx[queue[j]][queue[j]] = ~queue[j - 1];
}
mtrx[last_pt][last_pt] = w[last_pt];
}
}
for (int i = 0; i < n; i++) {
if (mtrx[i][i] > 0) {
res += mtrx[i][i];
}
else {
tmp_prt = ~mtrx[i][i];
res += mtrx[i][tmp_prt];
}
}
std::cout << res << std::endl;
return 0;
}
```
I hope this helps!
阅读全文