From 34b2099b3ea3658c1d7087dcd286b114e62fc4d5 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 23 Mar 2022 14:34:15 +0800 Subject: [PATCH] =?UTF-8?q?P2389=20=E7=94=B5=E8=84=91=E7=8F=AD=E7=9A=84?= =?UTF-8?q?=E8=A3=81=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R72132358 --- Luogu/P2389/P2389.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Luogu/P2389/P2389.cpp diff --git a/Luogu/P2389/P2389.cpp b/Luogu/P2389/P2389.cpp new file mode 100644 index 00000000..4f12a362 --- /dev/null +++ b/Luogu/P2389/P2389.cpp @@ -0,0 +1,33 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505; + +int n, k, sum[N], f[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> k; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + sum[i] = sum[i - 1] + x; + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= k; j++) { + for (int l = j - 1; l <= i; l++) { + f[i][j] = std::max({f[i][j], f[i - 1][j], f[l][j - 1] + (sum[i] - sum[l])}); + } + } + } + + cout << f[n][k] << endl; + + return 0; +}