subset-sum

Is this variant of the subset sum problem easier to solve?

落爺英雄遲暮 提交于 2020-01-19 07:39:11
问题 I have a problem related to the subset sum problem and am wondering if the differences make it easier, i.e. solvable in a reasonable amount of time. Given a value V, a set size L, and a sequence of numbers [1,N] S, how many size L subsets of S sum to less than V? This is different than the subset sum problem in three ways: I care how many subsets are less than a given value, not how many are equal . The subset sizes are fixed. I care how many sets sum to less than V, not just whether any

Is this variant of the subset sum problem easier to solve?

江枫思渺然 提交于 2020-01-19 07:38:13
问题 I have a problem related to the subset sum problem and am wondering if the differences make it easier, i.e. solvable in a reasonable amount of time. Given a value V, a set size L, and a sequence of numbers [1,N] S, how many size L subsets of S sum to less than V? This is different than the subset sum problem in three ways: I care how many subsets are less than a given value, not how many are equal . The subset sizes are fixed. I care how many sets sum to less than V, not just whether any

Calculating Minimal Subset With Given Sum

醉酒当歌 提交于 2020-01-17 01:12:45
问题 I was doing a problem in Scala and this is the summary of the task statement: There is a list of integers (of length N, 0 < N < 10^5) and another integer S (0 < S < 10^15). You are required to find the minimal size of the minimal subset of the given list of which the sum of elements (in the subset) is greater than or equal to S. Input is given as below: 4 4 12 8 10 4 4 13 30 100 Output for above example: 1 2 3 -1 First line is length of array, the second is the array of integers (0 < A[i] <

Sum of product of all possible subsets of array

廉价感情. 提交于 2020-01-01 04:55:23
问题 I have written a code to find Sum of product of all possible subsets of array. I'm getting the expected output but I'm not able to make it fast enough to clear time related test cases. Can anyone help me in optimizing my code for speed? First input (testCases) is the number of testcases. Depending on number of testcase, we will have size of array (size) and array elements (set). For example, a valid input would be: 1 3 2 3 5 where: 1 is the number of testcases. 3 is the size of the test set

Algorithm to find subset within two sets of integers whose sums match

给你一囗甜甜゛ 提交于 2019-12-29 04:01:06
问题 I'm looking for an algorithm which can take two sets of integers (both positive and negative) and find subsets within each that have the same sum. The problem is similar to the subset sum problem except that I'm looking for subsets on both sides. Here's an example: List A {4, 5, 9, 10, 1} List B {21, 7, -4, 180} So the only match here is: {10, 1, 4, 9} <=> {21, 7, -4} Does anyone know if there are existing algorithms for this kinda problems? So far, the only solution I have is a brute force

Subset sum variant with a non-zero target sum

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 18:34:24
问题 I have an array of integers and need to apply a variant of the subset sum algorithm on it, except that instead of finding a set of integers whose sum is 0 I am trying to find a set of integers whose sum is n . I am unclear as to how to adapt one of the standard subset sum algorithms to this variant and was hoping for any insight into the problem. 回答1: This is subset sum problem, which is NP-Complete (there is no known efficient solution to NP-Complete problems), but if your numbers are

Maximum subset sum with two arrays

时光怂恿深爱的人放手 提交于 2019-12-23 12:38:48
问题 I am not even sure if this can be done in polynomial time. Problem: Given two arrays of real numbers, A = (a[1], a[2], ..., a[n]), B = (b[1], b[2], ..., b[n]), (b[j] > 0, j = 1, 2, ..., n) and a number k , find a subset A' of A (A' = (a[i(1)], a[i(2)], ..., a[i(k)])) , which contains exactly k elements, such that, (sum a[i(j)])/(sum b[i(j)]) is maximized, where j = 1, 2, ..., k . For example, if k == 3 , and {a[1], a[5], a[7]} is the result, then (a[1] + a[5] + a[7])/(b[1] + b[5] + b[7])

custom partition problem

荒凉一梦 提交于 2019-12-23 10:54:31
问题 Could some one guide me on how to solve this problem. We are given a set S with k number of elements in it. Now we have to divide the set S into x subsets such that the difference in number of elements in each subset is not more than 1 and the sum of each subset should be as close to each other as possible. Example 1: {10, 20, 90, 200, 100} has to be divided into 2 subsets Solution:{10,200}{20,90,100} sum is 210 and 210 Example 2: {1, 1, 2, 1, 1, 1, 1, 1, 1, 6} Solution:{1,1,1,1,6}{1,2,1,1,1}

Recursion: Understanding (subset-sum) inclusion/exclusion pattern

浪子不回头ぞ 提交于 2019-12-23 04:59:12
问题 I need to understand how this recursion work, I understand simple recursion examples but more advanced ones is hard. Even thought there are just two lines of code I got problem with... the return statement itself. I just draw a blank on how this works, especially the and/or operator. Any insight is very welcome. bool subsetSumExists(Set<int> & set, int target) { if (set.isEmpty()) { return target == 0; } else { int element = set.first(); Set<int> rest = set - element; return subsetSumExists

Number of distinct sums from non-empty groupings of (possibly very large) lists

旧街凉风 提交于 2019-12-22 01:23:33
问题 Assume that you are given a set of coin types (maximum 20 distinct types) and from each type you have maximum 10^5 instances, such that the total number of all the coins in your list is maximum 10^6. What is the number of distinct sums you can make from non-empty groupings of these coins. for example, you are given the following lists: coins=[10, 50, 100] quantity=[1, 2, 1] which means you have 1 coin of 10, and 2 coins of 50, and 1 coin of 100. Now the output should be possibleSums(coins,