dfs的一道特别的题,思考起来比较难,不过没错,很正确,应该还有更好的方法
#include <bits/stdc++.h>
#define int long long
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();
k++;
}else if(str[k]=='|')
{
k++;
res=max(res,dfs());
}else if(str[k]==')')
{
break;
}else
{
k++;
res++;
}
}
return res;
}
signed main()
{
cin>>str;
cout<<dfs();
return 0;
}