UVa 10130

The problem wants to know the sum of maximum price that can be gained by every person i consuming no more than wi weight.

Explanation
This is a classic knapsack dp problem. For every test case, we'll run knapsack for every member in the group. The state will be (index,remaining_weight) where index denotes the i'th product(price and weight) and remaining_weight denotes the weight we can afford to buy.

Now, if remaining_weight=0 then we can not take anything else, again if index=n then all items are considered. The two are the base cases.

So, if arr[index].weight > remaining_weight, then we'll ignore this and go to (index+1,remaining_weight) state.

If (arr[index].weight <= remaining_weight) then we have two choice, ignore that particular index and go to (index+1,remaining_weight) state or take that product and go to arr[index].price+(index+1,remaining_weight-arr[index].weight) state. We'll take the maximum of these two choices. (NoooRa__)

Finally we'll sum up every one's knapsack output.

Gotchas

 * One particular product can be bought by more than one person but only once.

Implementations
dp table will be dp[1001][100*30+1].