Advertisement
STANAANDREY

alternator

Sep 3rd, 2020
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ///****************
  4. //THE ALTERNATOR
  5. #define NMAX 23
  6. int n, k, st[NMAX];
  7. bitset<NMAX> bs;
  8.  
  9. void doDaOps() {
  10.     for (int i = 1; i <= k; i++)
  11.         bs[st[i]] = true;
  12.     cout << bs << endl;
  13.     bs = 0;
  14. }
  15.  
  16. void backTr(int k) {
  17.     if (k - 1 == ::k) {
  18.         doDaOps();
  19.         return;
  20.     }
  21.     for (int i = st[k - 1] + 1; i <= n; i++) {
  22.         st[k] = i;
  23.         backTr(k + 1);
  24.     }
  25. }
  26.  
  27. int main() {
  28.     cin >> n >> k;
  29.     assert(n < NMAX - 2 && n >= k);
  30.     backTr(1);
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement