aboutsummaryrefslogtreecommitdiff
path: root/works/solutions/acwing/3-2.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-24 15:32:25 +0800
committercrupest <crupest@outlook.com>2021-02-24 15:32:25 +0800
commita14a096c787a71f6e60a108f9640b6127b997404 (patch)
tree8b1d3ac568d85e20e2c06cca9cdb8bc95433464a /works/solutions/acwing/3-2.cpp
parent765a27fc5678f3ea5ee89a7ea826dceec6aeced1 (diff)
downloadcrupest-a14a096c787a71f6e60a108f9640b6127b997404.tar.gz
crupest-a14a096c787a71f6e60a108f9640b6127b997404.tar.bz2
crupest-a14a096c787a71f6e60a108f9640b6127b997404.zip
import(solutions): Add acwing problem 4 (aka multiple pack problem).
Diffstat (limited to 'works/solutions/acwing/3-2.cpp')
-rw-r--r--works/solutions/acwing/3-2.cpp8
1 files changed, 2 insertions, 6 deletions
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]);
}
}