From 3a252921605ec4e4aa0003eaa44ae6d4e588ac0c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 5 Apr 2022 19:19:33 +0800 Subject: [PATCH] =?UTF-8?q?5.=20=E5=A4=9A=E9=87=8D=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20II?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13024172/ --- AcWing/5/5.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 AcWing/5/5.cpp diff --git a/AcWing/5/5.cpp b/AcWing/5/5.cpp new file mode 100644 index 00000000..3372efb3 --- /dev/null +++ b/AcWing/5/5.cpp @@ -0,0 +1,36 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int M = 2005; + +int n, m, f[M]; +std::vector> a; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> m; + for (int i = 1, v, w, s; i <= n; i++) { + cin >> v >> w >> s; + + for (int k = 1; k <= s; k <<= 1) { + s -= k; + a.push_back(std::make_pair(k * v, k * w)); + } + if (s > 0) a.push_back(std::make_pair(s * v, s * w)); + } + + for (int i = 0; i < a.size(); i++) { + for (int j = m; j >= a[i].first; j--) { + f[j] = std::max(f[j], f[j - a[i].first] + a[i].second); + } + } + + cout << f[m] << endl; + + return 0; +}