Store the value in dp array
ans = max ( ans , left + maxweight ( s , i , pre , dp ) , right + maxweight ( i + 1 , e , pre , dp ) ) NEW_LINE if left > right : NEW_LINE ans = max ( ans , right + maxweight ( i + 1 , e , pre , dp ) ) NEW_LINE dp [ key ] = ans NEW_LINE