CF 917A The Monster 【括号匹配】

【链接】:CF

Examples
inputCopy
((?))
outputCopy
4
inputCopy
??()??
outputCopy
7

说明
For the first sample testcase, the pretty substrings of s s are:

"(?" which can be transformed to "()".
"?)" which can be transformed to "()".
"((?)" which can be transformed to "(())".
"(?))" which can be transformed to "(())".
For the second sample testcase, the pretty substrings of s s are:

"??" which can be transformed to "()".
"()".
"??()" which can be transformed to "()()".
"?()?" which can be transformed to "(())".
"??" which can be transformed to "()".
"()??" which can be transformed to "()()".
"??()??" which can be transformed to "()()()".

【题意】:
给你一个字符串只包含'(' 、‘ )’ 、‘ ?’三种字符,?你可以按需求转换成‘(’或’)‘
定义一个区间为正确的括号序列,当且仅当对该区间进行如下操作之后,该序列为空:每次删除序列中一对相邻的左右括号(),直到删到不能再删
Input
一个长度不超过5000的字符串
Output
能转换成正确的括号序列的子区间数量
【分析】:
【代码】:

猜你喜欢

转载自www.cnblogs.com/Roni-i/p/9215580.html
今日推荐