|  | 
|  | 
| вернуться в форум | If you are having trouble Послано urmat  26 окт 2020 22:19dp[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
 | 
 | 
|