Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <assert.h>
- #define NMAX 64
- void mkAndPrintComb(int n, int k, const int arr[]) {
- assert(n <= 64 && k <= n);
- int cnt = 0;
- for (uint64_t state = 0; state < (1 << n); state++) {
- if (__builtin_popcount(state) != k) {
- continue;
- }
- printf("#%d: ", ++cnt);
- for (int i = 0; i < 64; i++) {
- if (1 & (state >> i)) {
- printf("%d ", arr[i]);
- }
- }
- putchar('\n');
- }
- }
- int main(void) {
- int n, k;
- scanf("%d%d", &n, &k);
- static int arr[NMAX];
- for (int i = 0; i < n; i++) {
- scanf("%d", arr + i);
- }
- mkAndPrintComb(n, k, arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement