for rest of the 2d matrix
for ( int i = 1 ; i < row ; i ++ ) { for ( int j = 1 ; j < col ; j ++ ) { cost [ i , j ] += Math . Min ( cost [ i - 1 , j - 1 ] , Math . Min ( cost [ i - 1 , j ] , cost [ i , j - 1 ] ) ) ; } }