多学习。

【递归】Acwing1225.正则问题(递归搜索树)

题目

题解

#include <iostream>

using namespace std;

int k;
string str;

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 ++ ; //跳过当前'x'
            res ++ ;
        }
    }
    return res;
}

int main()
{
    cin >> str;
    cout << dfs() << endl;
    return 0;
}
posted @ 2022-04-19 16:44  czyaaa  阅读(29)  评论(0)    收藏  举报