From 3952c7b3590f9d5542058a61476b080fc349c518 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 12 Nov 2021 16:57:13 +0800 Subject: [PATCH] =?UTF-8?q?P1006=20[NOIP2008=20=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?]=20=E4=BC=A0=E7=BA=B8=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R62341478 --- Luogu/P1006/P1006.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Luogu/P1006/P1006.cpp diff --git a/Luogu/P1006/P1006.cpp b/Luogu/P1006/P1006.cpp new file mode 100644 index 00000000..caa079eb --- /dev/null +++ b/Luogu/P1006/P1006.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int n, m, w[55][55], f[55][55][55][55]; + +int main() { + cin >> m >> n; + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + cin >> w[i][j]; + } + } + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + for (int k = i + 1; k <= m; k++) { + for (int l = 1; l < j; 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 == j && k == l) f[i][j][k][l] -= w[i][j]; + } + } + } + } + cout << f[m - 1][n][m][n - 1] << endl; + return 0; +}