What is wrong with this DP matrix sum. It keeps giving the wrong answer:
int solve(int i, int j) {
if (i < 0 || j < 0) return 0;
if (i == 0) return mat[0][j-1] + solve(0, j-1);
if (j == 0) return mat[i-1][0] + solve(i-1, 0);
return mat[i-1][j-1] + solve(i-1, j) + solve(i, j-1);
}
@Lalaland For a 3x3 matrix, the indices will be [0..2][0..2] but in the program i and j are passed in as, for example, solve(3, 3). So in your example you will be accessing an out of bounds area. That's why I was doing i-1 and j-1.