Go through all the supermasks

Revision en3, by rembocoder, 2020-10-26 23:42:03

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?

Tags submasks, overmasks, over-masks, masks, bitmasks

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English rembocoder 2020-10-26 23:42:03 5
en2 English rembocoder 2020-02-11 20:38:05 3 Tiny change: ') thread is shown ' -> ') thread it is shown ' (published)
ru3 Russian rembocoder 2020-02-11 20:36:28 0 (опубликовано)
en1 English rembocoder 2020-02-11 20:35:00 574 Initial revision for English translation (saved to drafts)
ru2 Russian rembocoder 2020-02-11 20:31:19 15 Мелкая правка: 'в [этой](ht' -> 'В [этой](ht'
ru1 Russian rembocoder 2020-02-11 20:28:40 597 Первая редакция (сохранено в черновиках)