From 99e2e923d0c77b02f3fb4ff648ea916954868606 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- store/works/solutions/acwing/5.cpp | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 store/works/solutions/acwing/5.cpp (limited to 'store/works/solutions/acwing/5.cpp') diff --git a/store/works/solutions/acwing/5.cpp b/store/works/solutions/acwing/5.cpp new file mode 100644 index 0000000..a88fba6 --- /dev/null +++ b/store/works/solutions/acwing/5.cpp @@ -0,0 +1,49 @@ +#include +#include + +int N, V; +int v[1001]; +int w[1001]; +int s[1001]; +int states[2001]; + +void CompletePack(int v, int w) { + for (int j = v; j <= V; j++) { + states[j] = std::max(states[j], states[j - v] + w); + } +} + +void ZeroOnePack(int v, int w) { + for (int j = V; j >= v; j--) { + states[j] = std::max(states[j], states[j - v] + w); + } +} + +int main() { + std::cin >> N >> V; + + for (int i = 1; i <= N; i++) { + std::cin >> v[i] >> w[i] >> s[i]; + } + + for (int i = 1; i <= N; i++) { + if (v[i] * s[i] >= V) { + CompletePack(v[i], w[i]); + } else { + int k = 1; + int amount = s[i]; + + while (k < amount) { + ZeroOnePack(k * v[i], k * w[i]); + amount -= k; + k *= 2; + } + + ZeroOnePack(amount * v[i], amount * w[i]); + } + } + + std::cout << states[V]; + + return 0; +} -- cgit v1.2.3