Problem 2583 --Balanced Sequence

2583: Balanced Sequence

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Chiaki has n strings s1,s2,…,sn consisting of '(' and ')'. A string of this type is said to be balanced:
+ if it is the empty string
+ if A and B are balanced, AB is balanced,
+ if A is balanced, (A) is balanced.
Chiaki can reorder the strings and then concatenate them get a new string t. Let f(t) be the length of the longest balanced subsequence (not necessary continuous) of t. Chiaki would like to know the maximum value of f(t) for all possible t.
 
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤105) -- the number of strings.
Each of the next n lines contains a string si (1≤|si|≤105) consisting of `(' and `)'.
It is guaranteed that the sum of all |si| does not exceeds 5×106.
For each test case, output an integer denoting the answer.
2
1
)()(()(
2
)
)(
4
2

推荐代码 查看2583 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$99 $ms] 刘欢@计算机科学与技术161 269285 2018-08-07 21:31:34
内存最少[$3396 $KB] 淡意的温柔 606319 2020-07-09 15:20:48
第一AC 刘欢@计算机科学与技术161 269285 2018-08-07 21:31:34
第一挑战 刘欢@计算机科学与技术161 269285 2018-08-07 21:31:34

赛题来源/所属竞赛 HDU N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛