Knapsack problem/Unbounded/Python dynamic programming: Difference between revisions

Content added Content deleted
m (→‎Ancillary module: Fixed typo (independant→ independent))
imported>Katsumi
Line 6: Line 6:
===Brute force, single size attribute===
===Brute force, single size attribute===
A brute-force solution for items with only one 'size' attribute would look like the following and would not scale:
A brute-force solution for items with only one 'size' attribute would look like the following and would not scale:
<syntaxhighlight lang="python">
<lang python>from operator import itemgetter as iget
from operator import itemgetter as iget
from itertools import product
from itertools import product
from random import shuffle
from random import shuffle
Line 418: Line 419:
Size = makesize('wt vol')
Size = makesize('wt vol')
x,y = Size(*[1,2]), Size(*[3,4])
x,y = Size(*[1,2]), Size(*[3,4])
</syntaxhighlight>
</lang>