0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00
Baoshuo Ren 2021-11-11 14:24:27 +08:00 committed by Baoshuo Ren
parent 4b68402aaf
commit 81deeb7ac3
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

24
AcWing/1027/1027.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <bits/stdc++.h>
using namespace std;
int n, r, c, k, w[15][15], f[15][15][15][15];
int main() {
cin >> n;
while (cin >> r >> c >> k, r && c && k) {
w[r][c] = k;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
for (int l = 1; l <= n; l++) {
f[i][j][k][l] = max({f[i - 1][j][k - 1][l], f[i - 1][j][k][l - 1], f[i][j - 1][k - 1][l], f[i][j - 1][k][l - 1]}) + w[i][j] + w[k][l];
if (i == k && j == l) f[i][j][k][l] -= w[i][j];
}
}
}
}
cout << f[n][n][n][n] << endl;
return 0;
}