In this thread it is shown how to go though all the submasks of a given mask without extra space or time. I needed to do the same thing for the overmasks, but I did not find anything. Based on the formula mask ^ (~mask) = -1
, my brother gave me this code:
for (int over = (1 << n) - 1; over > 0; over = ((over - mask - 1) & ~mask) + mask) {
cout << over << " ";
}
It really works. But can I simplify it, so it could be easier remembered during the contest?
Genial, thank you.
you want the overmasks of $$$S$$$ (i.e.: the masks of which $$$S$$$ is submask). I think it's the same as the NOT ($$$\text{~}$$$) of submasks of $$$\text{~} S$$$. Correct me if I'm wrong.
This post has no comment newer than 8 months ago. How did it appear under "Recent actions"?
Probably someone posted a comment and deleted it.
Or OP made an edit.