Help with a little sorting algorithm

We have an array of floats
float values[10]={1.23,2.12,3.52,4.12,2.5,10.6,1.27,1.38,0.49,0.21};

how can we get the numbers that if added together give the closest sum to an X number let’s say 12?

ideally each number should only be used once…

then get the next best sum from the remaining numbers etc…

This is apparently called a knapsack problem

http://rosettacode.org/wiki/Knapsack_problem/0-1#C.2B.2B

I thought to post it here - if I figure it out -as an example.

:hankey:

has anybody dealt with a similar problem before?