1 2 3 4 5 6 7 8 9 10 11 12 13 14
| void printf_subset(int s){ for(int i = 0;i < n;i++){ if(s & (1 << i))printf("%d ",i); } printf("\n"); } void Comb(int k){ int comb = (1 << k) - 1; while (comb < 1 << n) { printf_subset(comb); int x = comb & -comb, y = comb + x; comb = ((comb&~y) / x >> 1) | y; } }
|