1 2 3 4 5 6 7 8 9 10 11 12 13 14 | inline int ctz(int a) { int r = 0; while (!(a % 2)) a >>= 1, r++; return r; } int main() { int p = (1 << k) - 1; int maxp = (1 << n) - 1; while (p <= maxp) { int t = p | (p - 1); p = (t + 1) | (((~t & -~t) - 1) >> (ctz(p) + 1)); } } | cs |
nCk 조합 모두 참조하기
2018. 3. 28. 10:14