推 oin1104: 大師 07/12 15:05
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 清空
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.173.211.221 (美國)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720767228.A.6BD.html