Acwing93: https://www.acwing.com/problem/content/95/
https://www.acwing.com/problem/content/95/
这一题输出要求升序,vecotr<vector<int,int>>sort居然可以将里层的vector排序,amazing~
Code:
#include<bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define x first
#define y second
const int inf = 0x3f3f3f3f;
#define int long long
const int N = 30;
int n, m;
vector<vector<int>> ans;
void sol() {
cin >> n >> m;
for (int i=0; i< 1<<n; i++){
int k = 0;
for (int j=0; j<n; j++){
if(i >> j & 1) k++;
}
if(k!=m) continue;
vector<int> v;
for (int j=0; j<n; j++){
if(i >> j & 1) v.push_back(j+1);
}
ans.push_back(v);
}
sort(ans.begin(), ans.end());
for (auto v : ans){
for (auto u : v){
cout << u << ' ';
}
cout << '\n';
}
}
signed main(){
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
int T_T=1;
// cin >> T_T;
while (T_T--) sol();
return 0;
}