1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include<bits/stdc++.h> using namespace std;
int n;
vector<int> chosen;
void calc(int x){ if (x == (n + 1) ) { for(auto i = 0; i < chosen.size(); ++i) { cout << chosen[i] << " "; } cout << '\n'; return; } calc(x + 1); chosen.push_back(x); calc(x + 1); chosen.pop_back(); }
int main(){ cin >> n; calc(1); }
|