You have item types. Item has weight , value , and quantity limit . Find the maximum value you can fit in a knapsack of capacity .
For example: items with capacity . You can take up to 3 of the first item and up to 2 of the second. The simple solution adds another loop over quantities, but that's . When is large, this times out.