Optimal way of filling 2 knapsacks?

后端 未结 3 442
天命终不由人
天命终不由人 2020-12-08 11:28

The dynamic programming algorithm to optimally fill a knapsack works well in the case of one knapsack. But is there an efficient known algorithm that will optimally fill 2 k

3条回答
  •  不思量自难忘°
    2020-12-08 12:00

    The original DP assumes you mark in the dp array that values which you can obtain in the knapsack, and updates are done by consequently considering the elements.
    In case of 2 knapsacks you can use 2-dimensional dynamic array, so dp[ i ][ j ] = 1 when you can put weight i to first and weight j to second knapsack. Update is similar to original DP case.

提交回复
热议问题