Related
In following contests:
这是经典的区间动态规划。设字符串为 s,长度为 n。令 dfs(l,r) 表示把子串 s[l..r] 改成合法配方的最少修改次数。
空区间代价为 0。对非空区间,枚举与位置 l 配对的右端点 i(l<i≤r),把 s[l] 与 s[i] 配成一对括号,再分别处理内部 s[l+1..i−1] 与右侧 s[i+1..r]:
dfs(l,r)=l<i≤rmin(dfs(l+1,i−1)+cost(s[l],s[i])+dfs(i+1,r))一份配方由四类括号字符组成:( 与 )、[ 与 ]、{ 与 }、< 与 >。称一个字符串为合法配方,当且仅当它满足下列规则之一:
( 配 )、[ 配 ]、{ 配 }、< 配 >。In following contests:
By signing up a CodeFun2000 universal account, you can submit code and join discussions in all online judging services provided by us.