dp
with the same dimensions as matrix
and fill the last row of dp
with the values of the last row of matrix
.(row, col)
in the current row, calculate the minimum sum of the falling path by considering the values directly below and the diagonally left and right cells in the dp
array.dp[row][col]
with the calculated minimum sum.dp
table, the first row of dp
will contain the minimum falling path sums starting from each cell in the first row of matrix
.dp
as the result.