summaryrefslogtreecommitdiff
path: root/acwing/2-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
commit39ae14dadf02109368ffeca4351828b7a79907df (patch)
tree2c0da1845699bd87e3a77a1532ba8a7dc03cab1f /acwing/2-2.cpp
parent9ac8e6f0fc6797c46396e40b794c2ffab8431d44 (diff)
downloadsolutions-39ae14dadf02109368ffeca4351828b7a79907df.tar.gz
solutions-39ae14dadf02109368ffeca4351828b7a79907df.tar.bz2
solutions-39ae14dadf02109368ffeca4351828b7a79907df.zip
Add acwing problem 4 (aka multiple pack problem).
Diffstat (limited to 'acwing/2-2.cpp')
-rw-r--r--acwing/2-2.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/acwing/2-2.cpp b/acwing/2-2.cpp
index de812f4..fb0fb3b 100644
--- a/acwing/2-2.cpp
+++ b/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]);
}
}