ok, so this is my problem...
i have an array of items, which i want to sum to x or above in a most efficient way...
is there a way for doing this? cause all the values are 64 bit ints.
i tried recursion but it's slow cause i can have up to 200 items :( helppp!!
gregorynoob 2 Junior Poster in Training
Recommended Answers
Jump to Postwhy use recursion when a simple loop will do. Loops are always faster than recursion (and less memory/stack intensive too).
Jump to Postthe general knapsack problem and the subset sum problem are NP-hard, but not NP-incomplete. so there are no polynomial-time algorithms. but it is one of the easy NP-complete problems to solve.
it can be solved (in pseudo-polynomial time) using dynamic programming.
AFAIK, using a Branch and bound algorithm …
All 6 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
gregorynoob 2 Junior Poster in Training
VernonDozier 2,218 Posting Expert Featured Poster
gregorynoob 2 Junior Poster in Training
vijayan121 1,152 Posting Virtuoso
VernonDozier 2,218 Posting Expert Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.