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 29 30 31 32
| #include<bits/stdc++.h> using namespace std;
int n, m;
vector<int> chosen;
void calc(int x){ if ( (chosen.size() > m) || (chosen.size() + (n - x + 1) < m) ) return; if (x == n + 1) { for(auto i = 0; i < chosen.size(); ++i) { cout << chosen[i] << " "; } cout << '\n'; return; } chosen.push_back(x); calc(x + 1); chosen.pop_back(); calc(x + 1); }
int main(){ cin >> n >> m; calc(1); }
|