提交时间:2023-11-18 09:51:51

运行 ID: 111070

#include<iostream> #include<string> #include<set> using namespace std; set<string> st; int n, a[1010]; bool b[1010]; void f(int x = 0, int u = -114514, int l = 0){ if(x == n){ if(l < 2) return; string s = ""; for(int i = 0; i < n; i++) if(b[i]){ s += (a[i] + '0'); s += ' '; } s = s.substr(0, s.size() - 1); st.insert(s); return; } if(a[x] >= u) b[x] = 1; if(a[x] >= u) f(x + 1, a[x], l + 1); b[x] = 0; f(x + 1, u, l); } int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } f(); int ti = 0; for(auto t: st){ ti++; cout << t; if(ti < st.size()) cout << endl; } return 0; }