subset-sum

Subset-sum problem in PHP with MySQL

时光总嘲笑我的痴心妄想 提交于 2019-12-21 21:32:17
问题 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 php form and the php function should give him a list of all possible combinations of songs which add up to the given time ±X min. So if the user wants to listen to 1 hour of music ±5 minutes he would enter 60 minutes and 5 minutes of threshold into

Subset sum with special conditions

拟墨画扇 提交于 2019-12-21 20:37:30
问题 (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 question like this here) I need to find if the smallest possible S that is the sum of some subset of X[i] that is >= T (some target value, smaller than the sum of the full set). The set isn't very large (about 40 elements), but still too big for

Subsets with equal sum

≯℡__Kan透↙ 提交于 2019-12-21 06:36:14
问题 I want to calculate how many pairs of disjoint subsets S1 and S2 (S1 U S2 may not be S) of a set S exists for which sum of elements in S1 = sum of elements in S2. Say i have calculated all the subset sums for all the possible 2^n subsets. How do i find how many disjoint subsets have equal sum. For a sum value A, can we use the count of subsets having sum A/2 to solve this ? As an example : S ={1,2,3,4} Various S1 and S2 sets possible are: S1 = {1,2} and S2 = {3} S1 = {1,3} and S2 = {4} S1 =

Compare a Number with sum of subset of numbers

梦想与她 提交于 2019-12-21 05:39:20
问题 I am looking a guidance of your gurus to find out a way to Compare a Number with a sum of subset of numbers like DECLARE L_NUM_TO_COMPARE NUMBER := 0; L_NUM_SUBSET NUMBER := 0; BEGIN FOR MAIN_REC IN ( SELECT 1 ID, 25150 ASSIGN_AMT FROM DUAL UNION ALL SELECT 2 ID, 19800 ASSIGN_AMT FROM DUAL UNION ALL SELECT 3 ID, 27511 ASSIGN_AMT FROM DUAL ) LOOP L_NUM_TO_COMPARE := MAIN_REC.ASSIGN_AMT; DBMS_OUTPUT.PUT_LINE( L_NUM_TO_COMPARE); FOR C IN ( SELECT 1 ID, 7120 WORK_AMT FROM DUAL UNION ALL SELECT 2

find a solution to subset sum using dynamic programming

我与影子孤独终老i 提交于 2019-12-20 14:41:33
问题 What I want to do I want to find a subset of an array that sums to a target T . I also want to use to a dynamic programming approach (and a bottom-up solution at that) to do this. What I currently have Currently I only found a way to see if amongst all subsets of size N , whether or not there is at least one subset that has the desired sum. See code below. public boolean solve(int[] numbers, int target) { //Safeguard against invalid parameters if ((target < 0) || (sum(numbers) < target)){

Subsets of a given Set of Integers whose sum is a Constant N : Java

瘦欲@ 提交于 2019-12-20 05:59:17
问题 Given a set of integers, how to find a subset that sums to a given value...the subset problem ? Example : S = {1,2,4,3,2,5} and n= 7 Finding the possible subsets whose sum is n. I tried to google out found many links,but were not clear. How can we solve this in java and what is the data structure to be used and its complexity ? 回答1: I wont give you any code, but explain how it works. Run a loop from 0 to (2^k-1) For each value in 1, a 1 in its binary representation indicates that this value

Generate lexicographic series efficiently in Python

柔情痞子 提交于 2019-12-20 05:15:19
问题 I want to generate a lexicographic series of numbers such that for each number the sum of digits is a given constant. It is somewhat similar to 'subset sum problem'. For example if I wish to generate 4-digit numbers with sum = 3 then I have a series like: [3 0 0 0] [2 1 0 0] [2 0 1 0] [2 0 0 1] [1 2 0 0] ... and so on. I was able to do it successfully in Python with the following code: import numpy as np M = 4 # No. of digits N = 3 # Target sum a = np.zeros((1,M), int) b = np.zeros((1,M), int

Generate lexicographic series efficiently in Python

我只是一个虾纸丫 提交于 2019-12-20 05:15:06
问题 I want to generate a lexicographic series of numbers such that for each number the sum of digits is a given constant. It is somewhat similar to 'subset sum problem'. For example if I wish to generate 4-digit numbers with sum = 3 then I have a series like: [3 0 0 0] [2 1 0 0] [2 0 1 0] [2 0 0 1] [1 2 0 0] ... and so on. I was able to do it successfully in Python with the following code: import numpy as np M = 4 # No. of digits N = 3 # Target sum a = np.zeros((1,M), int) b = np.zeros((1,M), int

Fast solution to Subset sum algorithm by Pisinger

僤鯓⒐⒋嵵緔 提交于 2019-12-17 15:42:59
问题 This is a follow-up to my previous question. I still find it very interesting problem and as there is one algorithm which deserves more attention I'm posting it here. From Wikipedia: For the case that each xi is positive and bounded by the same constant, Pisinger found a linear time algorithm. There is a different paper which seems to describe the same algorithm but it is a bit difficult to read for me so please - does anyone know how to translate the pseudo-code from page 4 ( balsub ) into

Algorithm to find a consecutive sub-sequence whose sum would be a asked number M from a sequence of numbers in O(n)

南笙酒味 提交于 2019-12-14 02:54:38
问题 Hi I have been trying to solve this problem for some time now. Lets say we have an array of positive numbers and we were given a value M. Then our goal is to find if there is a consecutive sub sequence in the array of positive numbers such that the sum of the sequence is exactly equal to sum M. If A[1],A[2],....A[n] is an array then we have to find if there exist i and j such that A[i]+...+A[j] = M. I am trying to get the O(n) solution using greedy approach. 回答1: I believe you can solve this