I have a knapsack problem with specified knapsack capacity for weight and weights count.
I need an algorithm that packs weights to knapsack when knapsack capacity is C, needed weights count is N and there is a list of weights. Sorting of weights doesn't matter. It would be best if algorithm is recursive.
For example:
I have knapsack witch can hold only 3 weights and they have to weight 10 and I have these weights: 9, 8, 7, 2, 1. The correct (and only) answer is 7, 2, 1.
It would be best if someone write pseudocode, but its ok if its any of the common programing languages.
P.S. Any tips its appreciated as well :)
[EDIT]I need algorithm that gives answer with exactly the N weights count which weights exactly C.