Here ( i + j ) indicate the current power of 2 in path that is 2 ^ ( i + j )
if ( mat [ i , j ] == 1 ) { dp [ i , j ] = ( int ) ( Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) + Math . Pow ( 2 , i + j ) ) ; } else { dp [ i , j ] = Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) ; } } }