From 9b611935f540752dbedce19a0889ea6dd54725cd Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 6 Apr 2022 16:37:01 +0800 Subject: [PATCH] =?UTF-8?q?282.=20=E7=9F=B3=E5=AD=90=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13071367/ --- AcWing/282/282.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 AcWing/282/282.cpp diff --git a/AcWing/282/282.cpp b/AcWing/282/282.cpp new file mode 100644 index 00000000..19a4fe96 --- /dev/null +++ b/AcWing/282/282.cpp @@ -0,0 +1,33 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 305; + +int n, a[N], sum[N], f[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + + sum[i] = sum[i - 1] + a[i]; + } + + for (int i = 2; i <= n; i++) { + for (int l = 1, r = i; r <= n; l++, r++) { + f[l][r] = 0x3f3f3f3f; + for (int k = l; k < r; k++) { + f[l][r] = std::min(f[l][r], f[l][k] + f[k + 1][r] + sum[r] - sum[l - 1]); + } + } + } + + cout << f[1][n] << endl; + + return 0; +}