I have a problem which is bothering me. It is not necessary a Java problem, it is a problem of finding an algorithm which does the right work.
The problem is: I have a multitude of numbers ( doubles ) and a limit that is also a double. I want to obtain a sequence of numbers, from those crowd ( multitude ) whose sum is the closest to the limit. I'll make an example to be more clear;
Ex1. 40,7,4,4 and 50 the limit => the best solution [40,4,4] is 48 = 40 + 4 + 4 the nearest number close to the limit
Ex2. 30,20,15,15,15,15 and 90 the limit => solution [30,15,15,15,15]
Thanks in advance
0 · ·