Boundary elements of a Matrix
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Maximum path sum in matrix
Given a matrix of N * M. Find the maximum path sum in matrix. The maximum path is sum of all elements from first row to last row where you are allowed to move only down or diagonally to left or right. You can start from any element in first row.
Examples:
Solutie
We are given a matrix of N * M. To find max path sum first we have to find max value in first row of matrix.
Store this value in res. Now for every element in matrix update element with max value which can be included in max path.
If the value is greater then res then update res. In last return res which consists of max path sum value.
Output:
Time Complexity: O(N*M)