arrays - Partial sum lookup / partial sum set assignment -
i have following problem solve. as input have 2 decimal arrays. sum of elements of both of them equal. actuall problem assign values 1 array second 1 partial sums - if element 1 array sum of number of elements second array - should assigned each other.
sample1:
array1: 25.0, 25.0, 50.0, 50.0 array2: 50.0, 100.0
expected result: 50.0 sum of 25.0 , 25.0, 100.0 sum of 50.0 , 50.0
(0->0,1; 1->2,3)
sample2:
array1: 20.0, 70.0, 80.0, 130.0 array2: 100.0, 200.0
expected result: 100 = 20+80, 200 = 70+130 (0->0,2; 1->1,3)
idea return assigned array element indexes , return less assingments possible.
this called subset sum problem.
unfortunately np-complete, meaning have check possible combinations.
however, if problem has small quantity of partial sums (such examples) brute force away.
moron correct, not np-complete problem require checking possible combinations.
believe subset sum 1 does.
Comments
Post a Comment