Advertisement
sherry_ahmos

Untitled

Nov 20th, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <map>
  9. #include <set>
  10. #include <unordered_map>
  11. #include <unordered_set>
  12. using namespace std;
  13.  
  14. #define ll long long
  15. #define nl "\n"
  16. #define cy cout << "YES\n"
  17. #define cn cout << "NO\n"
  18. #define sz(s) s.size()
  19. #define all(v) v.begin(), v.end()
  20. #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
  21. #define cout(vec) for (int i = 0; i < n && cout << 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, m;
  31. vector<vector<int>> vec1;
  32. ll arr[15][15];
  33. vector<int> v;
  34. void rec(int i, int j)
  35. {
  36.     if (i == n || j == m)
  37.         return;
  38.     if (i == n - 1 && j == m - 1)
  39.     {
  40.         vec1.push_back(v);
  41.         v.pop_back();
  42.         return;
  43.     }
  44.     v.push_back(arr[i][j]);
  45.     rec(i + 1, j);
  46.     rec(i, j + 1);
  47.     v.pop_back();
  48. }
  49. void solve()
  50. {
  51.     cin >> n >> m;
  52.     for (int i = 0; i < n; i++)
  53.         for (int j = 0; j < m; j++)
  54.             cin >> arr[i][j];
  55.     rec(0, 0);
  56.     sort(all(vec1));
  57.     for (int i = 0; i < sz(vec1); i++)
  58.     {
  59.         for (int j = 0; j < sz(vec1[i]); j++)
  60.         {
  61.             cout << vec1[i][j] << " ";
  62.         }
  63.         cout << "\n";
  64.     }
  65. }
  66.  
  67. int main()
  68. {
  69.     sherry();
  70.     int t = 1;
  71.     // cin >> t;
  72.     while (t--)
  73.     {
  74.         solve();
  75.     }
  76.     return 0;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement