my problem is: for given n, k - positive integers and f - bitmask (k <= n, log(f) < n) find all bitmasks m so that log(m) < n and count_of_ones(m) == k and m & f = 0. For example, if we had a set S={0,1,2,3,4}, then solution for n=5, k=2 and f=0b01010 would represent 2-element combinations of S-{1,3}. My current solution is to find masks for n'=n-count_of_ones(f), k'=k and f'=0 (using this algorithm) and then 'stretch' them to fit my conditions like this:
for(scaled_comb=comb; f > 0; f&=(f-1)) {
b = f&(-f);
scaled_comb = ((scaled_comb&~(b-1))<<1)|(scaled_comb&(b-1));
}
As You can see, stretching one bitmask takes O(count_of_ones(f)). Is there any way to speed it up? Thanks ;)