1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/删除子字符串的最大得分 [maximum-score-from-removing-substrings].html
2022-03-29 12:43:11 +08:00

47 lines
1.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个字符串 <code>s</code> 和两个整数 <code>x</code> 和 <code>y</code> 。你可以执行下面两种操作任意次。</p>
<ul>
<li>删除子字符串 <code>"ab"</code> 并得到 <code>x</code> 分。
<ul>
<li>比方说,从 <code>"c<strong>ab</strong>xbae"</code> 删除 <code>ab</code> ,得到 <code>"cxbae"</code> 。</li>
</ul>
</li>
<li>删除子字符串<code>"ba"</code> 并得到 <code>y</code> 分。
<ul>
<li>比方说,从 <code>"cabx<strong>ba</strong>e"</code> 删除 <code>ba</code> ,得到 <code>"cabxe"</code> 。</li>
</ul>
</li>
</ul>
<p>请返回对 <code>s</code> 字符串执行上面操作若干次能得到的最大得分。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>s = "cdbcbbaaabab", x = 4, y = 5
<b>输出:</b>19
<strong>解释:</strong>
- 删除 "cdbcbbaaa<strong>ba</strong>b" 中加粗的 "ba" ,得到 s = "cdbcbbaaab" ,加 5 分。
- 删除 "cdbcbbaa<strong>ab</strong>" 中加粗的 "ab" ,得到 s = "cdbcbbaa" ,加 4 分。
- 删除 "cdbcb<strong>ba</strong>a" 中加粗的 "ba" ,得到 s = "cdbcba" ,加 5 分。
- 删除 "cdbc<strong>ba</strong>" 中加粗的 "ba" ,得到 s = "cdbc" ,加 5 分。
总得分为 5 + 4 + 5 + 5 = 19 。</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>s = "aabbaaxybbaabb", x = 5, y = 4
<b>输出:</b>20
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= x, y &lt;= 10<sup>4</sup></code></li>
<li><code>s</code> 只包含小写英文字母。</li>
</ul>