set - Finding a greatest pair of combinations of numbers to reach a given sum -
as subject says, how find greatest pair of combination sum given set of number? below example.
we given number set {1, 2, 3, 4, 5}. can generate 2^5 combinations out of them. here want find 2 combinations sum equal, , possibly greatest.
example)
{1, 2} = {3} = sum 3
{1, 3} = {4} = sum 4
..
{1, 5} = {2, 4} = sum 6
..
{2, 5} = {3, 4} = sum 7
out of many combinations, {2, 5} , {3, 4} pair generates equal , greatest sum. here program wants return sum, 7.
constraints:
no element duplication. element included in 1 combination not included in paired combination. {1, 2, 4} = {3, 4} = sum 7 impossible 4 belongs both combinations.
all combination should consist of @ least 1 element.
total number of elements in given set 35. (i.e. 2^35 combinations available)
(fortunately) need find combinations sum less or equal rounded half of sum of element in given set. e.g) in example above, (1 + 2 + 3 + 4 + 5) / 2 = 7 maximum sum of combination want find out.
Comments
Post a Comment