1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计不同回文子序列 [count-different-palindromic-subsequences].html
2022-03-29 12:43:11 +08:00

42 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>给定一个字符串 s返回 <em><code>s</code>&nbsp;中不同的非空「回文子序列」个数 。</em></p>
<p>通过从 s&nbsp;中删除 0 个或多个字符来获得子序列。</p>
<p>如果一个字符序列与它反转后的字符序列一致,那么它是「回文字符序列」。</p>
<p>如果有某个 <code>i</code> , 满足&nbsp;<code>a<sub>i</sub>&nbsp;!= b<sub>i</sub></code><sub>&nbsp;</sub>,则两个序列&nbsp;<code>a<sub>1</sub>, a<sub>2</sub>, ...</code>&nbsp;&nbsp;<code>b<sub>1</sub>, b<sub>2</sub>, ...</code>&nbsp;不同。</p>
<p><strong>注意:</strong></p>
<ul>
<li>结果可能很大,你需要对&nbsp;<code>10<sup>9</sup>&nbsp;+ 7</code>&nbsp;取模 。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = 'bccb'
<strong>输出:</strong>6
<strong>解释:</strong>6 个不同的非空回文子字符序列分别为:'b', 'c', 'bb', 'cc', 'bcb', 'bccb'。
注意:'bcb' 虽然出现两次但仅计数一次。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = 'abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba'
<strong>输出:</strong>104860361
<strong>解释:</strong>共有 3104860382 个不同的非空回文子序列104860361 对 10<sup>9</sup> + 7 取模后的值。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>s[i]</code>&nbsp;仅包含&nbsp;<code>'a'</code>,&nbsp;<code>'b'</code>,&nbsp;<code>'c'</code>&nbsp;&nbsp;<code>'d'</code>&nbsp;</li>
</ul>