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
3
votes
3 answers

Subset whose sum is the smallest sum over a specific threshold

Given a collection of positive integers, I want the subset of those integers whose sum is the smallest sum that exceeds a threshold.
Adam Tegen
  • 25,378
  • 33
  • 125
  • 153
3
votes
3 answers

Efficient method to filter and add based on certain conditions (3 conditions in this case)

I have a data frame which looks like this a b c d 1 1 1 0 1 1 1 200 1 1 1 300 1 1 2 0 1 1 2 600 1 2 3 0 1 2 3 100 1 2 3 200 1 …
user2575429
  • 111
  • 2
  • 3
  • 8
3
votes
2 answers

Get all subsets that sum up to a value N in Prolog

This is the problem statement: Given a list of integers L and an integer S, generate all sublists whose elements add up to S. This is my solution: domains list=integer* clist=list* predicates sum(list,integer) …
rares.urdea
  • 650
  • 3
  • 16
  • 26
3
votes
2 answers

SUBSET-SUM, upper bound on number of solutions

As you probably know, the SUBSET-SUM problem is defined as determining if a subset of a set of whole numbers sum to a specified whole number. (there is another definition of subset-sum, where a group of integers sum to zero, but let's use this…
Mike
  • 58,961
  • 76
  • 175
  • 221
3
votes
2 answers

Linear algorithm to find minimum subset sum over a threshold

I have a collection of N positive integers, each bounded by a (relatively small) constant C. I want to find a subset of these numbers with the smallest sum greater than (or equal to) a value K. The numbers involved aren't terribly large (<100), but…
Athena
  • 203
  • 2
  • 8
3
votes
2 answers

Subset sum with special conditions

(Before you reply with a link to another SO question or close this as a duplicate please read the question carefully. This is different than the standard variant of this problem and I've searched for a long time so I'm pretty sure there isn't a…
cmpt
  • 31
  • 2
2
votes
1 answer

Efficient way of approaching the Subset Sum Problem with very large input sets

The problem I am facing: I need to find a way to deal with very large sets (3 to 10000000) of positive and negative ints, this seemed relatively impossible based off of previous experiments. However, I received hope when I found a Algorithm on…
2
votes
3 answers

Find all combinations that add up to given number python with list of lists

I've seen plenty of threads on how to find all combinations that add up to a number with one list, but wanted to know how to expand this such that you can only pick one number at a time, from a list of lists Question: You must select 1 number from…
Curious Student
  • 156
  • 1
  • 8
2
votes
1 answer

Subset-sum problem in PHP with MySQL

following Problem: I have a MySQL database with songs in it. The database has the following structure: id INT(11)(PRIMARY) title VARCHAR(255) album VARCHAR(255) track INT(11) duration INT(11) The user should be able to enter a specific time into a…
DcBexter
  • 21
  • 4
2
votes
1 answer

Efficient way to solve subset sum variation

Given an integer array, find the maximum number of sums of adjacent elements that are divisible by n. Example 1: input: long[] array = [1, 2, 3], n = 7 output: 0 Example 2: input: long[] array = [1, 2, 4], n = 7 output: 1 Example 3: input: long[]…
Enzo
  • 29
  • 3
2
votes
1 answer

Maximum Sum of elements of array which is not divisible by M, deleting/avoiding at most K consequtive array elements

Given: N, K, M and A(array) N = No. of elements in the array K = Maximum consequtive array elements that can be avoided/not considered in the answer |A| = N Starting from the last index of the array, you have to find the maximum sum that can be…
2
votes
1 answer

Use FFT to find all possible fixed-size subset sums

I need to solve the following problem: given an integer sequence x of size N, and a subset size k, find all the possible subset sums. A subset sum is the sum of elements in the subset. If elements in x are allowed to appear many times (up to k of…
user2961927
  • 1,290
  • 1
  • 14
  • 22
2
votes
4 answers

Find smallest subset sum matching another subset sum

I have a real-world problem (not homework!) that requires finding the sum of a subset of set A that equals the sum of a subset of some other set B. A very similar question with a helpful answer is here. Consider this example: @a = qw(200 2000 2000…
itzy
  • 11,275
  • 15
  • 63
  • 96
2
votes
1 answer

Get sum of group subset using pandas groupby

I have a dataframe as shown. Using python, I want to get the sum of 'Value' for each 'Id' group upto the first occurrence of 'Stage' 12. df = pd.DataFrame({'Id':[1,1,1,2,2,2,2], 'Date': ['2020-04-23', '2020-04-25', '2020-04-28',…
sak
  • 59
  • 4
2
votes
2 answers

Select rows where sum of a column equals a fixed value in R

I would like to get one (or all) possible combination of rows where sum of quantity column equals 20 here an example : structure(list(id = 1:10, quantity = c(11L, 1L, 4L, 12L, 19L, 10L, 3L, 13L, 16L, 14L)), class ="data.frame", row.names =…
Seif
  • 82
  • 1
  • 8