File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

optimal way to grab closest sum

 
omar bili
Ranch Hand
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a group of items, stored in an array, sorted according to the influence:
say

class person
name (string)
influence (number)
end class

i have a number x, i need to get a group of items where the sum of their influence is the closest to the given number x
example:

s1 70
s2 60
s3 25
s4 11

and x = 90:
so the result wil be s2 and s3 coz 70 + 25 = 95 is the closest sum to 90..
sorry for i dont know if such an algo has a name..
thanks for any help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java in General (intermediate)
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to find a subset of the numbers such that their sum is the largest possible value no greater than the given number X, that's called the backpack problem. I imagine your problem is mathematically equivalent.
 
omar bili
Ranch Hand
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a java implementation of this algorithm?
thanks
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can google for it, or just write your own.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic