Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Fastest way to "pick without replacement"

by LanX (Saint)
on Nov 20, 2020 at 10:55 UTC ( [id://11123885]=note: print w/replies, xml ) Need Help??


in reply to Fastest way to "pick without replacement"

seems to be a variation of the knapsack problem, so "best solution" is pretty ambitious.

I have good experience solving such stuff with a branch and bound algorithm combined with clever normalization (i.e. grouping similar cases) and caching in a hash (no need to descend a sub-tree which has already been investigated before).

In this case the normalization would be the sum of the partial solution, which would also be the key in the cache-hash.

for instance: 2+3 = 5 so once you can cache all further path for 5 without needing to branch.

2+3   +95 => $cache{5} = [ [95] ]

5     +95 => seen!

HTH! :)

PS: I wrote many posts about branch-and-bound here try searching the archives if interested.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found