From 556fb42e8af0b564423aba76b822f6512cb2cae6 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 28 Jan 2023 14:55:31 +0800 Subject: [PATCH] C - No Bug No Game https://codeforces.com/gym/104090/submission/190937443 --- Gym/104090/C/C.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Gym/104090/C/C.cpp diff --git a/Gym/104090/C/C.cpp b/Gym/104090/C/C.cpp new file mode 100644 index 00000000..078339f1 --- /dev/null +++ b/Gym/104090/C/C.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 3005; + +int n, k, p, w[N], f[N][N][2], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> k; + + memset(f, 0xc0, sizeof(f)); + f[0][0][0] = 0; + + for (int i = 1; i <= n; i++) { + cin >> p; + + std::copy_n(std::istream_iterator(cin), p, w + 1); + + for (int j = k - 1; j >= 0; j--) { + f[i][j][0] = f[i - 1][j][0]; + f[i][j][1] = f[i - 1][j][1]; + + if (j + p <= k) { // 全取 + f[i][j + p][0] = std::max(f[i][j + p][0], f[i - 1][j][0] + w[p]); + f[i][j + p][1] = std::max(f[i][j + p][1], f[i - 1][j][1] + w[p]); + } + + for (int l = 1; l < p && l <= k - j; l++) { + f[i][j + l][1] = std::max(f[i][j + l][1], f[i - 1][j][0] + w[l]); + } + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= k; j++) { + ans = std::max(ans, f[i][j][0]); + } + + ans = std::max(ans, f[i][k][1]); + } + + cout << ans << endl; + + return 0; +}