DP E
Maximize value below a specified weight limit backpack Issue But the space of weight limit is too large to make DP with weight as the defining region.
DP_E
The space of weights is 10^11
The space of values is 10^5
In DP_D, a function of value was created using weight as the domain of definition, and the maximum value was obtained That approach is too broad a definitional area for this issue.
So, conversely, we create a function of weight with value as the domain of definition.
Then find the largest subscript in the domain whose weight satisfies the constraint
https://gyazo.com/8f6820c6fa358d709bd62c806b3166fb
code:python
def solve(N, W, WV):
MAX_VALUE = N * 10 ** 3
weights = INF * (MAX_VALUE + 1) for i in range(N):
for j in range(MAX_VALUE - value + 1):
weights = next_weights
for i in range(MAX_VALUE, -1, -1):
return i
---
This page is auto-translated from /nishio/DP E. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.