Блог пользователя andrewtam

Автор andrewtam, история, 3 года назад, По-английски

Is there an efficient way to merge two knapsack DP tables which map max value to cost (or min cost to value)? The obvious solution would be to add each element from the second DP table into the first one at a time, but this would run O(W^2). Can we do better?

Теги dp
  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

If it's equivalent to adding $$$O(W)$$$ items into knapsack it can't be faster. But if you memorize which items were added into second knapsack DP, you can re-add them into first knapsack in $$$O(NW)$$$, which will be faster if $$$N < W$$$.