From 9e1a5ed3e751a4b13f93a0c4adfa73c8d0dc2b55 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 24 Nov 2020 21:28:36 +0800 Subject: [PATCH] =?UTF-8?q?P1004=20=E6=96=B9=E6=A0=BC=E5=8F=96=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R42421487 --- problem/P1004/P1004.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem/P1004/P1004.cpp diff --git a/problem/P1004/P1004.cpp b/problem/P1004/P1004.cpp new file mode 100644 index 00000000..5dae982c --- /dev/null +++ b/problem/P1004/P1004.cpp @@ -0,0 +1,26 @@ +#include + +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; +}