From a14a096c787a71f6e60a108f9640b6127b997404 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 24 Feb 2021 15:32:25 +0800 Subject: import(solutions): Add acwing problem 4 (aka multiple pack problem). --- works/solutions/acwing/3-2.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'works/solutions/acwing/3-2.cpp') diff --git a/works/solutions/acwing/3-2.cpp b/works/solutions/acwing/3-2.cpp index 6565c5b..c099838 100644 --- a/works/solutions/acwing/3-2.cpp +++ b/works/solutions/acwing/3-2.cpp @@ -14,12 +14,8 @@ int main() { } for (int i = 1; i <= N; i++) { - for (int j = 0; j <= V; j++) { - if (j >= v[i]) { - states[j] = std::max(states[j], states[j - v[i]] + w[i]); - } else { - states[j] = states[j]; - } + for (int j = v[i]; j <= V; j++) { + states[j] = std::max(states[j], states[j - v[i]] + w[i]); } } -- cgit v1.2.3