Advertisement
vlatkovski

Generate all subsets of {0, 1, 2, ..., N-1}

Oct 18th, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     vector<int> v(n);
  8.     for (int i = 0; i < n; ++i) v[i] = i;
  9.     int m = n;
  10.     while (m > 0) {
  11.         vector<int> curr(m);
  12.         copy(v.begin(), v.begin()+m, curr.begin());
  13.         do {
  14.             for (int x : curr) printf("%i ", x);
  15.             cout << '\n';
  16.         } while (next_permutation(curr.begin(), curr.end()));
  17.         m--;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement