From d9b86379176ee76b5c1dad7f525a356c8364b58d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 29 Mar 2022 18:19:51 +0800 Subject: [PATCH] =?UTF-8?q?P1541=20[NOIP2010=20=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?]=20=E4=B9=8C=E9=BE=9F=E6=A3=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R72696213 --- Luogu/P1541/P1541.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Luogu/P1541/P1541.cpp diff --git a/Luogu/P1541/P1541.cpp b/Luogu/P1541/P1541.cpp new file mode 100644 index 00000000..10f2842e --- /dev/null +++ b/Luogu/P1541/P1541.cpp @@ -0,0 +1,43 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 355, + M = 125; + +int n, m, a[N], b[5], f[M][M][M][M]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + for (int i = 1, x; i <= m; i++) { + cin >> x; + b[x]++; + } + + f[0][0][0][0] = a[1]; + for (int i = 0; i <= b[1]; i++) { + for (int j = 0; j <= b[2]; j++) { + for (int k = 0; k <= b[3]; k++) { + for (int l = 0; l <= b[4]; l++) { + f[i][j][k][l] = std::max({i ? f[i - 1][j][k][l] : 0, + j ? f[i][j - 1][k][l] : 0, + k ? f[i][j][k - 1][l] : 0, + l ? f[i][j][k][l - 1] : 0}) + + a[1 + i + j * 2 + k * 3 + l * 4]; + } + } + } + } + + cout << f[b[1]][b[2]][b[3]][b[4]] << endl; + + return 0; +}