提交时间:2023-11-18 09:10:09
运行 ID: 111010
#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 += ' '; } 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(); for(auto t: st){ cout << t << endl; } return 0; }