Let's start with the formalism:

To let $ W $ the total weight of our bag, $ 1, …, n $ be our elements, $ w_1, …, w_n $ their corresponding weights and $ v_1, …, v_n $ their corresponding values.

As is known, the backpack problem for integer weights can be solved by dynamic programming (or equivalently using recursion + memoization) with temporal complexity $ mathcal O (nW) $, from where $ W $ is the total weight that our bag can hold, and $ n $ is the number of elements.

For real numbers, however, the algorithm fails (imagine a billion objects with weight) $ <1 $, and $ W = 1 $). We can probably round them off in a clever way and then scale them back to integers, but that would go beyond the size of the problem in an improper way.

Another approach would be to use recursion instead of dynamic programming because the idea behind the algorithm still works – either the $ n $The article is in the optimal solution or not.

But even with the memo we can choose our weights so that all sums are counted

$$ sum_ {

begin {align}

I & in M ββ\

M & subseteq {1, .., n }

end {align}} w_i $$

are different, let us $ 2 ^ n $ Weight totals to remember.

Is there an optimal algorithm that preserves the pseudopolynom of time complexity?