Original Post
as i was trying to solve the subst sum problem and i did this ... i took all the combinations and summed them but these means that if i have n inputs then there are 2^n combinations !!!! this is very ineffecient !! i am sure there is a better way ... :(
bSet setUnion(const bSet & a ,const bSet & b)
{
bSet s(a);
for(int i =0 ;i<b.size(); i++)
s.insert(b);
return s;
}
bSet setPowerset(const bSet& s )
{
bSet p, t;
if (s.size() == 0)
return bSet();
if (s.size() == 1)
return p;
for (int i = s.size()-1; i >= 0; i--) {
for (int j = 0; j < s.size(); j++) {
if (j != i)
t.insert(s[j]);
}
p = setUnion(p, setPowerset(t));
t.clear();
}
p.insert(s);
return p;
}