+backtrace :: DPTable -> (Int, Weight) -> [Bag]
+backtrace table key@(numberBags, weight)
+ | numberBags == 0 = [Bag { bagValue = 0, bagWeight = weight }]
+ | weight == nextWeight = backtrace table nextKey
+ | otherwise = (backtrace table nextKey) ++ [includedBag]
+ where nextKey = backpointer (table!key)
+ (_, nextWeight) = nextKey
+ includedBag = Bag { bagWeight = weight - nextWeight
+ , bagValue = (value (table!key)) - value (table!nextKey)}
+