Kleitman–Wang algorithm