Here ( i + j ) indicate the current power of 2 in path that is 2 ^ ( i + j )
if ( mat [ i ] [ j ] == 1 ) { dp [ i ] [ j ] = Math . floor ( 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 ] ) ; } } }