2024-07-12
1717. Maximum Score From Removing Substrings
You are given a string s and two integers x and y. You can perform two types
of operations any number of times.
Remove substring "ab" and gain x points.
For example, when removing "ab" from "cabxbae" it becomes "cxbae".
Remove substring "ba" and gain y points.
For example, when removing "ba" from "cabxbae" it becomes "cabxe".
Return the maximum points you can gain after applying the above operations on
s.
抄解答.jpg
因为是要砍ab 或 ba
所以只处理a 或 b
ab 分数高就优先砍 ab 否则就先累积著
反之亦然
碰到不是 a, b 的东西的时候
因为绝对不会被消耗掉
所以要把之前累积的 a, b 清空