Can't be done. This problem can't be solved uniquely, UNLESS you can settle for ANY subset of numbers that will make the given sum. And even THAT problem is NP-complete.
Example: consider the following list of numbers:
1, 2, 4, 6, 7
If I tell you the subset sum is 10, you can make that two ways: 1+2+7, or 4+6. How would the program choose which one to return?
Now suppose all you demand is that the program return ANY subset of numbers that sums to your given total. Then the problem can be solved (though not uniquely), but this reduces exactly to a canonical problem in algorithms / theoretical computer science, the Subset Sum Problem. See:
http://en.wikipedia....set_sum_problemThis problem is part of a class of problems known as the "NP-complete" problems.
http://en.wikipedia....iki/NP-completehttp://en.wikipedia....lasses_P_and_NPI am not going to try to explain in brief terms what NP and NP-complete problems are (if you DO want to hear this, let me know), but suffice it to say that classifying a problem as NP-complete is tantamount to proving that it is among the hardest problems we know. We know of no efficient solutions to any NP-complete problem.
So you *can* solve this reduced form of your original problem, but it is very hard and the time it will take for your program to run will increase exponentially in the length of your list of numbers.
Hope this helps