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)/完美分割的方案数 [number-of-beautiful-partitions].html
2022-11-24 20:11:13 +08:00

52 lines
2.1 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>给你一个字符串&nbsp;<code>s</code>&nbsp;,每个字符是数字&nbsp;<code>'1'</code>&nbsp;&nbsp;<code>'9'</code>&nbsp;,再给你两个整数&nbsp;<code>k</code>&nbsp;<code>minLength</code>&nbsp;</p>
<p>如果对 <code>s</code>&nbsp;的分割满足以下条件,那么我们认为它是一个 <strong>完美</strong>&nbsp;分割:</p>
<ul>
<li><code>s</code>&nbsp;被分成 <code>k</code>&nbsp;段互不相交的子字符串。</li>
<li>每个子字符串长度都 <strong>至少</strong>&nbsp;&nbsp;<code>minLength</code>&nbsp;</li>
<li>每个子字符串的第一个字符都是一个 <b>质数</b> 数字,最后一个字符都是一个 <strong>非质数</strong>&nbsp;数字。质数数字为&nbsp;<code>'2'</code>&nbsp;<code>'3'</code>&nbsp;<code>'5'</code>&nbsp;&nbsp;<code>'7'</code>&nbsp;,剩下的都是非质数数字。</li>
</ul>
<p>请你返回 <code>s</code>&nbsp;<strong>完美</strong>&nbsp;分割数目。由于答案可能很大,请返回答案对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;<strong>取余</strong>&nbsp;后的结果。</p>
<p>一个 <strong>子字符串</strong>&nbsp;是字符串中一段连续字符串序列。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>s = "23542185131", k = 3, minLength = 2
<b>输出:</b>3
<b>解释:</b>存在 3 种完美分割方案:
"2354 | 218 | 5131"
"2354 | 21851 | 31"
"2354218 | 51 | 31"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>s = "23542185131", k = 3, minLength = 3
<b>输出:</b>1
<b>解释:</b>存在一种完美分割方案:"2354 | 218 | 5131" 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>s = "3312958", k = 3, minLength = 1
<b>输出:</b>1
<b>解释:</b>存在一种完美分割方案:"331 | 29 | 58" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k, minLength &lt;= s.length &lt;= 1000</code></li>
<li><code>s</code>&nbsp;每个字符都为数字&nbsp;<code>'1'</code>&nbsp;&nbsp;<code>'9'</code> 之一。</li>
</ul>