From 1bb46a2ec54dd7480a2f859c827bda02eb4e23d5 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 14 Oct 2024 21:06:35 +0800 Subject: [PATCH] :white_check_mark: P5662 100pts --- CMakeLists.txt | 3 ++- csp-backpack/main.cc | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 csp-backpack/main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index d57756f..30f6d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,5 @@ add_executable(Playground eating-snake/main.cc insert-sort/main.cc csp-decode/main.cc - palin/main.cc) + palin/main.cc + csp-backpack/main.cc) diff --git a/csp-backpack/main.cc b/csp-backpack/main.cc new file mode 100644 index 0000000..e30dcde --- /dev/null +++ b/csp-backpack/main.cc @@ -0,0 +1,25 @@ +#include +#include + +using namespace std; +#define maxn 10005 +#define M 105 +int dp[maxn]; +int w[M][M]; + +int main() { + int T, n, W; + cin >> T >> n >> W; + for (int i = 1; i <= T; i++) + for (int j = 1; j <= n; j++) // <- used to be i++ + cin >> w[i][j]; + for (int i = 1; i < T; i++) { + memset(dp, 0, sizeof dp); + for (int j = 1; j <= n; j++) + for (int k = w[i][j]; k <= W; k++) + dp[k] = max(dp[k], dp[k - w[i][j]] + w[i + 1][j] - w[i][j]); + W = max(dp[W] + W, W); + } + cout << W << endl; + return 0; +} \ No newline at end of file