ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1183. Brackets Sequence

If you are having trouble
Posted by urmat 26 Oct 2020 22:19
dp[N][N] - minimum number of added brackets, ok[l][r] - is [l, r] already solved, vector<pair<char, int>> add[N][N] - what and where brackets should be added to [l][r], to make it balanced.
make calc(l, r) function, if ok[l][r] then return dp[l][r],
if(l == r) then add[l][r] = {{reversed(s[l]), l}} dp[l][r] = 1
if(l + 1 == r and s[l] matches s[r]) then dp[l][r] = 0
if(s[l] == s[r]) you update dp[l][r] with dp[l + 1][r - 1]
or with dp[l][k] + dp[k + 1][r],
take care of already balanced strings