patternMinor
Subset sum with only two item types
Viewed 0 times
itemtypeswithtwosumsubsetonly
Problem
Suppose we have $r$ copies of the integer $a$ and $t$ copies of the integer $b$, and a capacity $C$. We would like to find the maximum sum of the given integers, that is at most $C$.
This is a special case of the subset sum problem. Since there are at most $(r+1)(t+1)$ possible sums, one can just check all of them and find the maximum sum that is at most $C$. But this takes time $O(r t)$, while the size of the input - if it is given in binary - is $\log{(r t a b)}$.
Is there an algorithm that solves the problem in time polynomial in the size of the binary representation of the input?
This is a special case of the subset sum problem. Since there are at most $(r+1)(t+1)$ possible sums, one can just check all of them and find the maximum sum that is at most $C$. But this takes time $O(r t)$, while the size of the input - if it is given in binary - is $\log{(r t a b)}$.
Is there an algorithm that solves the problem in time polynomial in the size of the binary representation of the input?
Solution
As kcsquared notes, this is an instance of integer linear programming (ILP) in two dimensions. Lenstra showed that ILP can be solved in polynomial time when the number of dimensions is constant; the special case of two dimensions was apparently proven earlier by Scarf. This proves that your program can be solved in polynomial time, as you were hoping.
Context
StackExchange Computer Science Q#145887, answer score: 2
Revisions (0)
No revisions yet.