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?? |
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
In Section
Seekers of Perl Wisdom
|
|