Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef tree<int,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define MOD 1000000007
- #define PI 3.14159265
- #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
- #define imin INT_MIN
- #define imax INT_MAX
- #define nl '\n'
- void Start_Crushing() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- //vector<int> dx = {0, 0, 1, -1, 1, 1, -1, -1}, dy = {1, -1, 0, 0, 1, -1, 1, -1};
- //vector<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};
- int n, m;
- vector<vector<int>> grid;
- ll maxPath(int x = 0, int y = 0, ll path = 0){
- if(x == n - 1 and y == m - 1)
- return path + grid[x][y];
- ll res = imin;
- if(x < n - 1)
- res = max(res, maxPath(x + 1, y, path + grid[x][y]));
- if(y < m - 1)
- res = max(res, maxPath(x, y + 1, path + grid[x][y]));
- return res;
- }
- void solve(){
- cin >> n >> m;
- grid.assign(n, vector<int>(m));
- for(auto& i : grid){
- for(auto& j : i) cin >> j;
- }
- cout << maxPath();
- }
- int main(){
- // freopen("cakes.in", "r", stdin);
- Start_Crushing();
- int t = 1;
- // /*is Single Test case?*/ cin >> t;
- while (t--) {
- solve();
- if(!t) break;
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement