Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define ll long long
- #define nl "\n"
- #define cy cout << "YES\n"
- #define cn cout << "NO\n"
- #define sz(s) s.size()
- #define all(v) v.begin(), v.end()
- #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
- #define cout(vec) for (int i = 0; i < n && cout << vec[i] << " "; i++)
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int n, m;
- vector<vector<int>> vec1;
- ll arr[15][15];
- vector<int> v;
- void rec(int i, int j)
- {
- if (i == n || j == m)
- return;
- if (i == n - 1 && j == m - 1)
- {
- vec1.push_back(v);
- v.pop_back();
- return;
- }
- v.push_back(arr[i][j]);
- rec(i + 1, j);
- rec(i, j + 1);
- v.pop_back();
- }
- void solve()
- {
- cin >> n >> m;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- cin >> arr[i][j];
- rec(0, 0);
- sort(all(vec1));
- for (int i = 0; i < sz(vec1); i++)
- {
- for (int j = 0; j < sz(vec1[i]); j++)
- {
- cout << vec1[i][j] << " ";
- }
- cout << "\n";
- }
- }
- int main()
- {
- sherry();
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement