提交时间:2023-11-18 10:35:38
运行 ID: 111113
#include<bits/stdc++.h> using namespace std; int n,a[114514],res[114514]; vector <vector <int> > ans; void dfs(int x,int len,int lst){ if (x > n && len <= 1){ return ; } if (x > n && len >= 2){ vector <int> vec; for (int i = 1;i <= len;i++){ vec.push_back(res[i]); } ans.push_back(vec); return ; } if (a[x] >= lst){ res[len + 1] = a[x]; dfs(x + 1,len + 1,a[x]); res[len + 1] = 0; } dfs(x + 1,len,lst); } bool cmp(vector <int> a,vector <int> b){ if (a.size() == b.size()){ for (int i = 0;i < min(a.size(),b.size());i++){ if (a[i] < b[i]){ return true; } if (a[i] > b[i]){ return false; } } } return a.size() < b.size(); } signed main(){ cin>>n; for (int i = 1;i <= n;i++){ cin>>a[i]; } dfs(1,0,0); sort(ans.begin(),ans.end(),cmp); //ans.erase(unique(ans.begin(),ans.end()),ans.end()); for (int i = 0;i < ans.size();i++){ for (int j = 0;j < ans[i].size();j++){ cout<<ans[i][j]<<' '; } cout<<'\n'; } return 0; }