Advertisement
sherry_ahmos

Untitled

Oct 27th, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <unordered_map>
  12. #include <unordered_set>
  13. using namespace std;
  14.  
  15. #define ll long long
  16. #define nl endl
  17. #define cy cout << "YES\n"
  18. #define cn cout << "NO\n"
  19. #define sz(s) s.size()
  20. #define all(v) v.begin(), v.end()
  21. #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
  22. #define cout(vec) for (int i = 0; i < n && cout << vec[i] << " "; i++)
  23.  
  24. void sherry()
  25. {
  26.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  27. #ifndef ONLINE_JUDGE
  28.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  29. #endif
  30. }
  31.  
  32. int n;
  33. vector<int> v, curr;
  34. vector<vector<int>> vec;
  35. bool valid()
  36. {
  37.     for (int i = 1; i < sz(curr); i++)
  38.     {
  39.         if (curr[i] <= curr[i - 1])
  40.             return false;
  41.     }
  42.     return true;
  43. }
  44. void rec(int i)
  45. {
  46.     if (i == sz(v))
  47.     {
  48.         if (!curr.empty())
  49.         {
  50.             if (valid())
  51.                 vec.push_back(curr);
  52.         }
  53.         return;
  54.     }
  55.     curr.push_back(v[i]);
  56.     rec(i + 1);
  57.     curr.pop_back();
  58.     rec(i + 1);
  59. }
  60.  
  61. void solve()
  62. {
  63.     cin >> n;
  64.     v.assign(n, 0);
  65.     cin(v);
  66.     rec(0);
  67.     sort(all(vec));
  68.     for (int i = 0; i < sz(vec); i++)
  69.     {
  70.         for (int j = 0; j < sz(vec[i]); j++)
  71.         {
  72.             cout << vec[i][j] << " ";
  73.         }
  74.         cout << endl;
  75.     }
  76. }
  77.  
  78. int main()
  79. {
  80.     sherry();
  81.     ll t = 1;
  82.     // cin >> t;
  83.     while (t--)
  84.     {
  85.         solve();
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement