bill lam wrote:
> I want to burn data files to dvd of 4.5G
>     ?.20#1000
> 146 755 79 852 854 439 660 257 60 594 246 478 713 318 151 92 178 260 90
> 862
>
> how to find the subset of numbers such that their sum is nearest but not
> exceeding 4500?
>
>

If you have n integer weights with a total weight W, you can do it by
dynamic programming in time O(nW).  See, for example

http://cgm.cs.mcgill.ca/~msuder/courses/360/lectures/integer-knapsack.html

This is usually done recursively with memoization: you may want to
consider something else in J.

For small n, you can calculate all sums with O(2^n).

Best wishes,

John

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to