There are N item to be moved and you have initial strength S. Each item has three properties, vi – the value of this item, ai – the strength cost to move this item, bi – the strength you will regain after moving this item. Your strength should be at least ai to move the ith item.
You maybe unable to move all items, so you want to find the maximum value that you can gain.
This problem can be solved by dp-knapsack with the items are first sorted in decreasing order of bi. Remember that dp-knapsack will work only when the item ordering is not important (so we don’t need to “look back” after processing each item), thus we need the preprocessing step.
Let’s observe the ordering of two items: item1 (a1, b1) and item2 (a2, b2). The after-strength if we take both items will always the same in spite of the ordering, but the total strength needed will be different depends on which bi is larger. If item1 is taken before item2, then the needed strength will be (a1 – b1 + a2). But if item2 is taken first, then the it will be (a2 – b2 + a1). It’s obvious that one with larger bi will yield the lowest needed strength.