Questions tagged [subset-sum]

In computer science, the subset sum problem is one of the important problems in complexity theory and cryptography.

In computer science, the subset sum problem is one of the important problems in complexity theory and cryptography.

424 questions
4
votes
1 answer

subset sum find all subsets that add up to a number

I have been learning dynamic programming, and I want to take the classic subset sum problem a little further by printing out all the subsets which add up to a number. How exactly would I go about doing this? As of now, I know how to print true or…
seanscal
  • 568
  • 2
  • 9
  • 33
4
votes
2 answers

Meal Plan Algorithm?

Let's say that I have a database of foods, each with an amount of Fat, Carbs and Protein. For example, let's say that I had this database: Item Fat Carbs Protein ================================================ Milk …
Luke
  • 61
  • 3
4
votes
3 answers

match elements to a list of sums

If I have an array of numbers and a list of sums that total the array elements, what's the most effective approach (or at least a not a brute force hack) for determining which of the elements are included in the sum? A simplified example might look…
4
votes
3 answers

sql server : select rows who's sum matches a value

here is table T :- id num ------- 1 50 2 20 3 90 4 40 5 10 6 60 7 30 8 100 9 70 10 80 and the following is a fictional sql select * from T where sum(num) = '150' the expected result is :- (A) id num ------- 1 50 8 …
armen
  • 1,253
  • 3
  • 23
  • 41
4
votes
2 answers

Modified Knapsack/Subset-Sum with same weight/values

I was working on a problem that has to deal with a special case of the Knapsack/Subset-Sum Problem. The problem is as follows: You have a set of bundle sizes in decreasing sizes that are random like: {47, 35, 22, ...}. You have value that is the…
MarcusM
  • 73
  • 7
4
votes
3 answers

Find sum of subset with multiplication

Let's say we have got a set {a_1, a_2, a_3, ..., a_n} The goal is to find a sum that we create in the following way: We find all subsets whose length is 3, then multiply each subset's elements (for the subset {b_1, b_2, b_3} the result will be…
4
votes
3 answers

Algorithm: Optimal combination of values to stay within range

I have the following math problem, which I need in an application, and I am wondering if there is an efficient way to find the best solution as opposed to an approximation. I have a list of positive and negative values. The sum of these values is…
Roel Vlemmings
  • 359
  • 2
  • 5
4
votes
1 answer

Finding number of permutations of 'p' numbers that sum to a given number 'n'

I am trying to solve a dynamic programming problem and part of the problem involves finding number of permutations of a set of 'p' numbers that will sum up to a number 'n'. Each number in the set of p numbers should be between 0 to n inclusive. For…
quirkystack
  • 1,387
  • 2
  • 17
  • 42
4
votes
3 answers

Understanding Sum of subsets

I've just started learning Backtracking algorithms at college. Somehow I've managed to make a program for the Subset-Sum problem. Works fine but then i discovered that my program doesn't give out all the possible combinations. For example : There…
3
votes
1 answer

Subset sum for exactly k integers?

Following from these question Subset sum problem and Sum-subset with a fixed subset size I was wondering what the general algorithm for solving a subset sum problem, where we are forced to use EXACTLY k integers, k <= n. Evgeny Kluev mentioned that…
Bober02
  • 15,034
  • 31
  • 92
  • 178
3
votes
4 answers

List of subsets of which their elements add up to n using recursion

I'm writing this function which I want to print all the sublists of a given list with integers. The sum of these integers should be equal to a given number n. There is also a help variable i which starts with value 0. Both the list and each sublist…
Loolooii
  • 8,588
  • 14
  • 66
  • 90
3
votes
4 answers

Anagram generation - Isnt it kind of subset sum?

Anagram: An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; Subset Sum problem: The problem is this: given a set of…
Shubham
  • 21,300
  • 18
  • 66
  • 89
3
votes
2 answers

Subset sum problem with known subset size and array being a range

I'm trying to find a fast way to solve the subset sum problem with a few modifications, I know the exact size of the subset I need to get the target number and I also know the input array to be a range from 1 to 2000. My questions is if there is any…
Fanfer123
  • 67
  • 11
3
votes
2 answers

Comparing returned vectors from recursion tree branches

Suppose I have a given sum, say sum = 4. I am also given a vector = {2,4}. There are two ways to generate the given sum from the given vector (elements may be reused). One way is just {4} cause 4 = 4. Second way is {2,2} cause 2 + 2 = 4. I have to…
Divyanshu Varma
  • 122
  • 3
  • 17
3
votes
0 answers

Finding the smallest sum between subset of array in java

I am trying to solve this problem where you are given a list of integers and you are expected to find 2 subsets of that list where the sum of the lists is minimized, the catch is the subsets must be the same length, or if it is an odd number input…
Noah Iarrobino
  • 1,435
  • 1
  • 10
  • 31