sorry
I have tried to dived the problem to smaller problems
i though it will be easy for you.
No it isn't; maximixing that a_i*w_i essentially demands another algorithm than
just finding feasible solutions. For the 0/1 Knapsack problem think along the
following (recursive) line:
Start with k == n.
- set up a sequence w_0, w_1, ... w_k
- the knapsack has volume W
- only the elements 0 ... k are allowed to be in the knapsack.
solve the two subproblems (this is the recursive step)
- w_0, w_1 ... w_k-1
- the knapsack has volume W-w_k
- ony elements 0 ... k-1 are allowed
and
- w_0, w_1 ... w_k-1
- the knapsack has volume W
- only element 0 ... k-1 are allowed
The value k starts at k == n.
for the second (locally optimal!) solution see if w_k still fits in the knapsack.
Take the better of the two solutions. The recursion ends when k < 0.
kind regards,
Jos