sak1b

https://leetcode.com/problems/minimum-path-sum

Dec 11th, 2020
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1.    
  2.     int fun(int i, int j, vector<vector<int>>& a)
  3.     {  
  4.         if(i>=m || j>=n)
  5.         {
  6.             return big;
  7.         }
  8.        
  9.         if(dp[i][j]!=-1)
  10.         {
  11.             return dp[i][j];
  12.         }
  13.  
  14.         if(i==m-1 && j==n-1)
  15.         {
  16.             return dp[i][j]=a[i][j];
  17.         }
  18.  
  19.         return dp[i][j]=min(fun(i+1,j,a),fun(i,j+1,a))+a[i][j];
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment