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 | b65d176c4c13fc916f09c192af97fc2edd5faa90 (patch) | |
tree | ffbf43549b5af3bf27f2020a25c7a032a5ee2a3c /works/solutions/acwing/3-2.cpp | |
parent | de8f16f524a160199c9dfbf78c26d9eb080b5e9a (diff) | |
download | crupest-b65d176c4c13fc916f09c192af97fc2edd5faa90.tar.gz crupest-b65d176c4c13fc916f09c192af97fc2edd5faa90.tar.bz2 crupest-b65d176c4c13fc916f09c192af97fc2edd5faa90.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.cpp | 8 |
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]);
}
}
|