Maximum sum path in a matrix from top | C # program for the above approach ; Function to find the maximum sum path in the grid ; Dimensions of grid [ , ] ; Stores maximum sum at each cell sum [ i , j ] from cell sum [ 0 , 0 ] ; Iterate to compute the maximum sum path in the grid ; Update the maximum path sum ; Return the maximum sum ; Driver Code
using System ; class GFG { static int MaximumPath ( int [ , ] grid ) { int N = grid . GetLength ( 0 ) ; int M = grid . GetLength ( 1 ) ; int [ , ] sum = new int [ N + 1 , M + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= M ; j ++ ) { sum [ i , j ] = Math . Max ( sum [ i - 1 , j ] , sum [ i , j - 1 ] ) + grid [ i - 1 , j - 1 ] ; } } return sum [ N , M ] ; } public static void Main ( String [ ] args ) { int [ , ] grid = { { 1 , 2 } , { 3 , 5 } } ; Console . Write ( MaximumPath ( grid ) ) ; } }