1 2 3 4 5 6 7 8 9 10 11 12
| int helper(vector<vector<int>>& A, vector<vector<int>>& dp, int r, int n, int c) { if(r == n) return 0; if(dp[r][c] != -1) return dp[r][c]; return dp[r][c] = A[r][c] + min(helper(A,dp,r + 1, n, c), helper(A,dp,r + 1, n, c + 1)); } int Solution::minimumTotal(vector<vector<int> > &A) { int n = A.size(); vector<vector<int>> dp(n,vector<int>(n,-1)); return helper(A,dp,0,n,0); }
|