0/1 Knapsack Algorithm

0

 



Fill up:

IF j < Wi : place upper value

IF j = Wi : max (upper value, Pi + column[0] of previous row)

IF j = Wi + 1: max (upper value, Pi + column[1] of previous row)

IF j = Wi + n: max (upper value, Pi + column[n] of previous row)

Traceback:

Select last value (max profit)

IF it came from up Go upper cell

ELSE Go left where value is current value - Pi and select the row

move to the value and repeat





Tags

Post a Comment

0Comments
Post a Comment (0)
Ads