0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:51:58 +00:00

P1004 方格取数

R42421487
This commit is contained in:
Baoshuo Ren 2020-11-24 21:28:36 +08:00 committed by Baoshuo Ren
parent 5946db5550
commit 9e1a5ed3e7
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

26
problem/P1004/P1004.cpp Normal file
View File

@ -0,0 +1,26 @@
#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;
}