Advertisement
sherry_ahmos

Untitled

Oct 26th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 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. ll nCr(ll n, ll r)
  33. {
  34.     if (n < r)
  35.         return 0;
  36.     ll res = 1;
  37.     for (ll i = 1; i <= r; i++)
  38.     {
  39.         res *= n--;
  40.         res /= i;
  41.     }
  42.     return res;
  43. }
  44. int n;
  45. vector<int> v;
  46. multiset<vector<int>> vec;
  47. vector<int> curr;
  48. void printVector(vector<int> myVector)
  49. {
  50.     if (myVector.size() > 0)
  51.     {
  52.         for (int i = 0; i < myVector.size(); i++)
  53.         {
  54.             cout << myVector[i] << " ";
  55.         }
  56.         cout << "\n";
  57.     }
  58. }
  59. void print(multiset<vector<int>> &multisetOfVectors)
  60. {
  61.    
  62. }
  63. void rec(int i)
  64. {
  65.     if (i == n)
  66.     {
  67.         vector<int> s = curr;
  68.         sort(s.begin(), s.end());
  69.         if (s == curr)
  70.             vec.insert(s);
  71.         return;
  72.     }
  73.     curr.push_back(v[i]);
  74.     rec(i + 1);
  75.     curr.pop_back();
  76.     rec(i + 1);
  77. }
  78.  
  79. void solve()
  80. {
  81.     cin >> n;
  82.     v = vector<int>(n);
  83.     cin(v);
  84.     rec(0);
  85. for (auto it = vec.begin(); it != vec.end(); it++)
  86.     {
  87.         printVector(*it);
  88.     }}
  89.  
  90. int main()
  91. {
  92.     sherry();
  93.     ll t = 1;
  94.     // cin >> t;
  95.     while (t--)
  96.     {
  97.         solve();
  98.     }
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement