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