Given an array of positive integers and an upper limit MAX, i have to find the sub-sequence with sum <= MAX. There can be many sub-sequences whose sum is <= MAX .
We have to find that one with max sum possible.
- I am not looking for the exponential-time solution. The array can
have upto 1-2k elements and MAXX can be very large, upto 10^9 or
something.
- Neither am i looking for the 0,1-knapsack approach. It works in
O(N^2) and i have to call this method around 1-2k times.
Can we do it any better?
Futher I would like to add I'm not looking for an algorithm that gives 100% accurate answers. I am trying to achieve a golden-mean between time-complexity and accuracy.
Any Ideas?
The more accurate the better. By this what I mean, I explain here below.
When ever a subset is found, it is removed from the total set.
The Next subset is formed from the remaining elements.
Suppose the subset formed sums to Y
As per the question Y should be <=MAX. Now lets take the difference of MAXX and Y,
X = MAXX - Y
AND we add it up to TOTAL i.e. we do for each each subset
TOTAL+=Y
We have to minimize X as much as we can.
Is there a way in which we can take advantage of the the following fact?
the remaining set is the total set minus the subset formed
Hope this explains the question.