Parenthesis Arrangement
传送门
Problem Statement
You are given a string S S S of length 2 N 2N 2N consisting of the characters ( and ). Let S i S_i Si denote the i i i-th character from the left of S S S.
You can perform the following two types of operations zero or more times in any order:
-
Choose a pair of integers ( i , j ) (i,j) (i,j) such that 1 ≤ i < j ≤ 2 N 1\leq i < j \leq 2N 1≤i<j≤2N. Swap S i S_i Si and S j S_j Sj. The cost of this operation is A A A.
-
Choose an integer i i i such that 1 ≤ i ≤ 2 N 1\leq i \leq 2N 1≤i≤2N. Replace S i S_i Si with
(or). The cost of this operation is B B B.
Your goal is to make S S S a correct parenthesis sequence. Find the minimum total cost required to achieve this goal. It can be proved that the goal can always be achieved with a finite number of operations.
What is a correct parenthesis sequence? A correct parenthesis sequence is a string that satisfies any of the following conditions:
- It is an empty string.
- It is formed by concatenating
(, A A A,)in this order where A A A is a correct parenthesis sequence. - It is formed by concatenating A A A and B B B in this order where A A A and

最低0.47元/天 解锁文章
443

被折叠的 条评论
为什么被折叠?



