fork download
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. using namespace std;
  4. int n, a[25];
  5. string k;
  6. vector<int> x;
  7. vector<string> v;
  8. vector<vector<int>> ans;
  9. void Try(int posa)
  10. {
  11. for (int i = posa + 1; i <= n; i++)
  12. {
  13. if (a[i] > a[posa])
  14. {
  15. x.push_back(a[i]);
  16. if (x.size() > 1)
  17. ans.push_back(x);
  18. Try(i);
  19. x.erase(x.end() - 1, x.end());
  20. }
  21. }
  22. }
  23. int main()
  24. {
  25. ios_base::sync_with_stdio(0);
  26. cin.tie(0);
  27. cin >> n;
  28. a[0] = 0;
  29. for (int i = 1; i <= n; i++)
  30. cin >> a[i];
  31. Try(0);
  32. for (int i = 0; i < ans.size(); i++)
  33. {
  34. k = "";
  35. for (int j = 0; j < ans[i].size(); j++)
  36. {
  37. k += to_string(ans[i][j]);
  38. k += " ";
  39. }
  40. v.push_back(k);
  41. }
  42. sort(v.begin(), v.end());
  43. for (int i = 0; i < v.size(); i++)
  44. cout << v[i] << endl;
  45. }
Success #stdin #stdout 0.01s 5244KB
stdin
4
6 3 7 11
stdout
3 11 
3 7 
3 7 11 
6 11 
6 7 
6 7 11 
7 11