mixture problem in medium concept

how to solve problems like mixture in medium level

please help

this is a dynamic programming problem. Can be solved similar to the classical matrix multiplication problem where you need to place brackets to minimize the number of multiplications.


its similiar to the standard matrix multiplication problem
you need to mantain two auxiliary table
1.) dp[n][n] //stores maximum smoke for subarry ai to aj is in dp[i][j]
2.) color[n][n] // stores color of all subarray ai to aj