How to find what numbers in a set add up to another given number?

algorithm, c#, np-complete, np-hard

Solution

This is the Subset Sum problem, which is NP-Complete. But that doesn't mean there isn't an algorithm for finding a subset sum.

Problem

Here's a problem that I seem to be running into working with an accounting system. I have a set of transactions, but their sum does not equal the amount that the accounting department thinks that it should. They are not questioning the math, just the transactions being included :p Is there an algorithm that would help me determine which transactions in the set should not be included in order for the sum to match a given amount. ``` Given Set: 2 4 5 7 Given Sum Amount: 13 Result Set: 2 4 7 ``` Edit: There's less than 100 transactions in the set. Does anyone have a C# example as there is not one on the Solving the NP-complete problem in XKCD question? Man, I should have gotten a CS degree.

Original source

Related problems