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

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


has anybody dealt with a similar problem before?