Advertisement
Ahmed_Negm

Untitled

Oct 8th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define nl '\n'
  9. #define sz(x) int(x.size())
  10. #define all(x) x.begin(),x.end()
  11. #define rall(s)  s.rbegin(), s.rend()
  12. #define getline(s) getline(cin>>ws,s)
  13. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define pi  3.141592653589793
  15. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  17.  
  18.  
  19. void Fast_IO(){
  20.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. // freopen("filename.in", "r", stdin);
  22. // freopen("filename.txt", "w", stdout);
  23. #ifndef ONLINE_JUDGE
  24.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27.  
  28. int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  29. int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  30.  
  31. int n,m;
  32. vector<vector<ll>> v;
  33. bool valid(int x,int y){
  34.     return x>=0&&x<n&&y>=0&&y<m;
  35. }
  36.  
  37. ll rec(int i=0,int j=0){
  38.     if(i==n-1&&j==m-1)return v[i][j];
  39.     if(!valid(i,j)) return (ll)1e-9;
  40.     return v[i][j]+max(rec(i+1,j),rec(i,j+1));
  41. }
  42.  
  43.  
  44. void solve(){
  45.     cin>>n>>m;
  46.     v.resize(n,vector<ll>(m));
  47.     for(int i=0;i<n;i++) {
  48.         for (int j = 0; j < m; j++) {
  49.             cin >> v[i][j];
  50.         }
  51.     }
  52.     cout<<rec(0,0);
  53.  
  54.  
  55. }
  56.  
  57. int main(){
  58.     Fast_IO();
  59.     int t =1;
  60. //cin>>t;
  61.     while(t--){
  62.         solve();
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement