For a sub - array from indices left , right . This innermost loop finds the last balloon burst
for ( int last = left ; last < right + 1 ; last ++ ) { dp [ left , right ] = Math . Max ( dp [ left , right ] , dp [ left , last - 1 ] + B [ left - 1 ] * B [ last ] * B [ right + 1 ] + dp [ last + 1 , right ] ) ; } } } return dp [ 1 , N ] ; }