For , try each balloon in as the last one to burst. Coins = + + .
The first two terms are coins from clearing the left and right. The last term is from bursting k when only i and j remain as neighbors. = max over all in of this expression. The formula tells you how to compute dp[i][j] from smaller ranges. Getting this right is the core of DP.