Input Matrix :
1 2 3
4 5 6
7 8 9
Output : 1 + 4 + 7 + 8 + 9 = 29
int[][] memo = new int[m][n];
for(int i = 1; i < m; i++){
memo[i][0] = memo[i-1][0] + grid[i][0];
}
for(int j = 1; j < n; j++){
memo[0][j] = memo[0][j-1] + grid[0][j];
}
memo
and use the information of the cells in the previous row / col to fill the current cell : for(int i = 1; i < m; i++){
for(int j = 1; j < n; j++){
memo[i][j] = grid[i][j] + Math.max(memo[i-1][j], memo[i][j-1]);
}
}
return memo[m-1][n-1];
public static int matrixMaxSumDP(int[][] grid) { }
C
Java
Python