Iterate through all possible values of k in range [ i + 1 , j - 1 ]
for ( int k = i + 1 ; k < j ; ++ k ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i , k ] + dp [ k , j ] + A [ i ] * A [ j ] ) ; } } }