Clear the String
HardRating 2000CodeforcesAdvanced DP (Bitmask, Digit, Interval)
Approach hintTry it first, then revealHide
Let dp[l][r] be the cost to clear s[l..r]. Either delete s[l] on its own, or erase it together with a later equal character s[k] after clearing s[l+1..k-1], giving dp[l+1][k-1] + dp[k][r]. O(n^3).