diff options
author | crupest <crupest@outlook.com> | 2021-02-24 15:32:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-24 15:32:25 +0800 |
commit | 39ae14dadf02109368ffeca4351828b7a79907df (patch) | |
tree | 2c0da1845699bd87e3a77a1532ba8a7dc03cab1f /acwing/2-2.cpp | |
parent | 9ac8e6f0fc6797c46396e40b794c2ffab8431d44 (diff) | |
download | solutions-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.cpp | 8 |
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]);
}
}
|