题目描述
blablabla
样例
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
string str;
int k;
int dfs()
{
int res=0;
while(k<str.size())
{
if(str[k]=='(')
{
k++;//跳过'('
res+=dfs();//表示括号里有多少x就加上多少x
k++;
//跳过')'//因为下面等有右括号的时候是直接break了,并没有跳过
//因为()是一对
//为什么不能在下面跳过右括号捏
//(xxxx|xxx) 这样理解,假如在|层里面遇到)就返回,确实能算出来|左右两边的值的最大值,但在|里面遇到),k++的话,
//回到( 的搜索完毕的那一层,(就遇不到)了,就是说()内的值无法正确更新;
}
else if(str[k]=='|')
{
k++;//跳过
res=max(res,dfs());//左右取最大值
}
else if(str[k]==')'){break;}
else
{
res++;
k++;
}
}
return res;
}
int main()
{
cin>>str;
cout<<dfs()<<endl;
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla