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 approach which tries every combination but it performs in Exponential time and I've had to put a hard limit on the number of elements to consider to avoid it from taking too long.
The only other solution I can think of is to run a factorial on both lists and look for equalities there but that is still not very efficient and takes exponentially longer as the lists get bigger.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…