Advertisement
sherry_ahmos

Untitled

Oct 26th, 2022
207
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 allv v.begin(), v.end()
  21. #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
  22.  
  23. void sherry()
  24. {
  25.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  26. #ifndef ONLINE_JUDGE
  27.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. }
  30. int n, r;
  31. multiset<vector<string>> vec;
  32. vector<string> v;
  33. vector<string> curr;
  34. void printVector(vector<string> myVector)
  35. {
  36.     for (auto element : myVector)
  37.         cout << element << ' ';
  38.     cout << "\n";
  39. }
  40. void print(multiset<vector<string>> &multisetOfVectors)
  41. {
  42.     for (auto it = multisetOfVectors.begin();
  43.          it != multisetOfVectors.end();
  44.          it++)
  45.     {
  46.         printVector(*it);
  47.     }
  48. }
  49. void rec(int i)
  50. {
  51.     if (i > r)
  52.     {
  53.         if (curr.size() == r)
  54.         {
  55.             vector<string> s = curr;
  56.             sort(s.begin(), s.end());
  57.             vec.insert(s);
  58.         }
  59.         return;
  60.     }
  61.     curr.push_back(v[i]);
  62.     rec(i + 1);
  63.     curr.pop_back();
  64.     rec(i + 1);
  65. }
  66. void solve()
  67. {
  68.     cin >> n >> r;
  69.     v = vector<string>(n);
  70.     cin(v);
  71.     rec(0);
  72.     print(vec);
  73. }
  74.  
  75. int main()
  76. {
  77.     sherry();
  78.     ll t = 1;
  79.     // cin >> t;
  80.     while (t--)
  81.     {
  82.         solve();
  83.     }
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement