From b65d176c4c13fc916f09c192af97fc2edd5faa90 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/2-2.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'works/solutions/acwing/2-2.cpp') diff --git a/works/solutions/acwing/2-2.cpp b/works/solutions/acwing/2-2.cpp index de812f4..fb0fb3b 100644 --- a/works/solutions/acwing/2-2.cpp +++ b/works/solutions/acwing/2-2.cpp @@ -14,12 +14,8 @@ int main() { } for (int i = 1; i <= N; i++) { - for (int j = V; j >= 0; 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; j >= v[i]; j--) { + states[j] = std::max(states[j], states[j - v[i]] + w[i]); } } -- cgit v1.2.3