1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int f[12][12][12][12], a[12][12], n, x, y, z; 6 7 int main() { 8 cin >> n >> x >> y >> z; 9 while (x != 0 || y != 0 || z != 0) { 10 a[x][y] = z; 11 cin >> x >> y >> z; 12 } 13 14 for (int i = 1; i <= n; ++i) { 15 for (int j = 1; j <= n; ++j) { 16 for (int k = 1; k <= n; ++k) { 17 for (int l = 1; l <= n; ++l) { 18 19 f[i][j][k][l] = max(max(f[i - 1][j][k - 1][l], f[i - 1][j][k][l - 1]), max(f[i][j - 1][k - 1][l], f[i][j - 1][k][l - 1])) + a[i][j] + a[k][l]; 20 if (i == k && l == j) f[i][j][k][l] -= a[i][j]; 21 } 22 } 23 } 24 } 25 cout << f[n][n][n][n] << endl; 26 return (0); 27 }