1. 程式人生 > >洛谷P3719 REXP 題解

洛谷P3719 REXP 題解

clas str span amp tdi signed fine long 字符串

題目

一道考驗遞歸的題目,在面對這種字符串處理的題時,還是應該用遞歸這種比較好看懂而且比較簡單寫的算法。

\(code\)

```c++
// luogu-judger-enable-o2

include

include

include

include

include

define lowbit(x) x & (-x)

using namespace std;
// luogu-judger-enable-o2

include

include

include

include

include

define int long long

using namespace std;
int digui(int ans)

{
char c;
while (cin >> c)
{
if (c == ‘)‘) return ans;
if (c == ‘a‘)
ans++;
if (c == ‘(‘)
ans += digui(0);
if (c == ‘|‘)
return ans = max(ans, digui(0));//要註意此時必須要return 因為如果不這樣的話,會使本來要求的最大值不對
}
return ans;
}
signed main()
{
printf("%lld", digui(0));
}

洛谷P3719 REXP 題解