Decision subset sum
Is there any subset that adds to T? Answer: yes or no. {1, 5, 6, 9, 11} → 15: yes (6 + 9).
Find every subset of a list that adds to a target, with the DP table and closest sums.
Enter your values below to get started.
Duplicates count as separate items: {5, 5} has 2 subsets that sum to 5.
Pick Any number of times for coin-change style problems.
Prices work: 19.99 is handled in whole cents, so no rounding errors.
With a target ≤ 40 and ≤ 14 numbers, the DP table tab draws the whole table.
A subset sum calculator finds which numbers from a list add up exactly to a target. Enter up to 100 numbers (decimals to 2 places, such as prices) and a target to get the number of solutions, every matching subset up to your limit, the dynamic programming (DP) table that proves the answer, and the closest sums above and below when no exact subset exists.
The subset sum problem asks whether some subset of a list of numbers adds up exactly to a target value T, and if so, which subset. For the set {3, 34, 4, 12, 5, 2} and T = 9, 2 subsets work: {4, 5} and {3, 4, 2}.
Subset sum is one of Richard Karp's 21 NP-complete problems (1972): no known algorithm solves every case in time polynomial in the number of bits of the input. A set of n numbers has 2n subsets, so 40 numbers already give 1,099,511,627,776 subsets to check by brute force.
The problem is a special case of the 0/1 knapsack problem where each item's value equals its weight.
The subset sum calculator fills a dynamic programming table of reachable sums, reads the answer from the cell for the full set and the target, then walks back through the table to list each subset. The method, from Richard Bellman's dynamic programming (1950s), takes n × T steps instead of 2n.
Decimals are multiplied by 100 (cents) so the table has whole-number columns.
ways[s] counts how many subsets reach each sum s, item by item.
A depth-first search guided by the table lists subsets with no dead ends, up to your limit.
With no exact match, the calculator reports the nearest reachable sum below and above T.
The subset sum recurrence says a sum s is reachable with the first i items when it was reachable without item i, or when s − ai was reachable without item i. The base case is dp[0][0] = true.
Replacing OR with + counts the subsets instead of testing them.
When each number can be reused, the 2nd term looks in the same row. Coins {1, 2, 5} make 11 in 11 ways.
There are 4 main types of subset sum problems: the decision version, the counting version, the unbounded version and the partition problem. All 4 use the same table with a different question asked of it.
Is there any subset that adds to T? Answer: yes or no. {1, 5, 6, 9, 11} → 15: yes (6 + 9).
How many subsets add to T? {1, 5, 6, 9, 11} has 2 subsets that sum to 15: {6, 9} and {1, 5, 9}.
Each number can repeat, as with coins. {1, 5, 6, 9, 11} reaches 15 in 11 ways.
Can the set split into 2 halves with equal sums? {1, 5, 6, 9, 11} totals 32: {5, 11} and {1, 6, 9} both sum to 16.
To solve a subset sum by hand, keep a list of reachable sums, start with {0}, and for each number add it to every sum already on the list; the target is reachable when it appears. Here is {2, 3, 7, 8, 10} with T = 11:
Subset sum is NP-complete, yet the dynamic programming solution runs in O(n·T) time, which is fast whenever the target T is small. This is called pseudo-polynomial time: the cost grows with the size of T itself, not with the number of digits in T.
With 30 numbers and T = 10,000, the table has 300,000 cells, while brute force checks 230 ≈ 1.07 billion subsets. With T = 1015, the table is too large and Horowitz–Sahni's meet-in-the-middle method (1974) is the better choice.
To use the subset sum calculator, enter the set, the target, how many solutions to list and whether numbers can repeat, then press Calculate. The result card shows how many solutions exist and the first one; the tabs show the steps, every listed subset and the DP table.
Up to 100 non-negative numbers; decimals up to 2 places.
The sum you want, for example 9 or 25.24.
List 1, 10, 50, 200 or 500 solutions. The count always covers all of them.
Once for classic subset sum, any number of times for coin change.
Subset sums answer any question of the form "which of these amounts add up to that total?" There are 5 common uses:
Classic subset sum problems and their answers.
| Set | Target | Answer | Calculator |
|---|---|---|---|
| {3, 34, 4, 12, 5, 2} | 9 | 2 subsets: {4, 5}, {3, 4, 2} | |
| {2, 3, 7, 8, 10} | 11 | 1 subset: {3, 8} | |
| {1, 2, …, 10} | 15 | 20 subsets | |
| {10, 20, 30, 40, 50} | 100 | 3 subsets | |
| {19.99, 5.49, 12.50, 7.25, 3.75} | 25.24 | {5.49, 12.50, 7.25} | |
| {1, 2, 5}, repeats | 11 | 11 combinations | |
| {6, 10, 15} | 7 | None (closest 6 and 10) |
Try each one, then reveal the answer or solve it in the calculator.
Which subsets of {15, 22, 14, 26, 32, 9, 16, 8} add up to 53?
Does any subset of {2, 4, 6, 8} sum to 9?
How many subsets of {1, 3, 5, 7, 9} sum to 16?
Can {1, 5, 6, 9, 11} be split into 2 groups with equal sums?
In how many ways can 1-, 2- and 5-cent coins make 11 cents?
What is the closest sum to 30 using {3, 34, 4, 12, 5, 2} once each?
Discover 67 free sum calculators across different categories. Find the right calculator for your needs.
Try a different name or choose another category.
A subset sum calculator is an online tool that finds which numbers from a list add up to a target sum. This subset sum calculator counts every solution, lists up to 500 of them, draws the dynamic programming table and gives the closest sums when no exact subset exists.
Solve the subset sum problem with dynamic programming: keep a table of reachable sums, start from sum 0, and for each number mark every old sum plus that number as reachable. The target is solvable when its cell is marked.
Yes, subset sum is NP-complete. Richard Karp included it among 21 NP-complete problems in 1972, but the O(n·T) dynamic programming method still solves it fast when the target T is small.
Yes, the subset sum calculator uses decimals with up to 2 places. It multiplies every value by 100 and works in whole cents, so 19.99 + 5.25 is exact.
No, not in the classic subset sum problem: each number is used at most once. Pick Any number of times for the unbounded version, as in coin change.
The subset sum calculator reports no exact solution and shows the closest reachable sums below and above the target, such as 6 and 10 for the set {6, 10, 15} and target 7.
A set of n numbers has 2ⁿ subsets, including the empty set. 10 numbers have 1,024 subsets and 30 numbers have 1,073,741,824.
Subset sum asks for a total exactly equal to T, and 0/1 knapsack maximizes value under a weight limit. Subset sum is the knapsack case where each item's value equals its weight.
The subset sum problem asks which numbers from a list add to a target, and the subset sum calculator answers it with a dynamic programming table, a full count of solutions and a list of subsets. Use the 0/1 mode for invoices and budgets, the unbounded mode for coins, and the closest sums when no exact match exists.
Not sure which version of the problem you have? Answer the questions below.