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