0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-26 17:32:11 +00:00
OI-codes/Luogu/P1004/P1004.cpp

27 lines
729 B
C++
Raw Normal View History

2020-11-24 13:28:36 +00:00
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z, f[12][12][12][12], a[12][12];
int main() {
cin >> n;
while (cin >> x >> y >> z, x || y || z) {
a[x][y] = z;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
for (int p = 1; p <= n; p++) {
f[i][j][k][p] = max({f[i - 1][j][k - 1][p], f[i - 1][j][k][p - 1], f[i][j - 1][k - 1][p], f[i][j - 1][k][p - 1]}) + a[i][j] + a[k][p];
if (i == k && p == j) {
f[i][j][k][p] -= a[i][j];
}
}
}
}
}
cout << f[n][n][n][n] << endl;
return 0;
}