1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-26 02:00:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/找出所有稳定的二进制数组 II [find-all-possible-stable-binary-arrays-ii].html

62 lines
2.9 KiB
HTML
Raw Normal View History

2024-04-30 10:04:49 +08:00
<p>给你 3 个正整数&nbsp;<code>zero</code>&nbsp;<code>one</code>&nbsp;&nbsp;<code>limit</code>&nbsp;</p>
<p>一个 <span data-keyword="binary-array">二进制数组</span> <code>arr</code> 如果满足以下条件,那么我们称它是 <strong>稳定的</strong> </p>
<ul>
<li>0 在&nbsp;<code>arr</code>&nbsp;中出现次数 <strong>恰好</strong>&nbsp;<strong>&nbsp;</strong><code>zero</code>&nbsp;</li>
<li>1 在&nbsp;<code>arr</code>&nbsp;中出现次数 <strong>恰好</strong>&nbsp;&nbsp;<code>one</code>&nbsp;</li>
<li><code>arr</code> 中每个长度超过 <code>limit</code>&nbsp;<span data-keyword="subarray-nonempty">子数组</span><strong>同时</strong> 包含 0 和 1 。</li>
</ul>
<p>请你返回 <strong>稳定</strong>&nbsp;二进制数组的 <em></em> 数目。</p>
<p>由于答案可能很大,将它对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;<b>取余</b>&nbsp;后返回。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>zero = 1, one = 1, limit = 2</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>两个稳定的二进制数组为&nbsp;<code>[1,0]</code>&nbsp;<code>[0,1]</code>&nbsp;,两个数组都有一个 0 和一个 1 ,且没有子数组长度大于 2 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">zero = 1, one = 2, limit = 1</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p>唯一稳定的二进制数组是&nbsp;<code>[1,0,1]</code>&nbsp;</p>
<p>二进制数组&nbsp;<code>[1,1,0]</code>&nbsp;<code>[0,1,1]</code>&nbsp;都有长度为 2 且元素全都相同的子数组,所以它们不稳定。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>zero = 3, one = 3, limit = 2</span></p>
<p><span class="example-io"><b>输出:</b>14</span></p>
<p><strong>解释:</strong></p>
<p>所有稳定的二进制数组包括&nbsp;<code>[0,0,1,0,1,1]</code>&nbsp;<code>[0,0,1,1,0,1]</code>&nbsp;<code>[0,1,0,0,1,1]</code>&nbsp;<code>[0,1,0,1,0,1]</code>&nbsp;<code>[0,1,0,1,1,0]</code>&nbsp;<code>[0,1,1,0,0,1]</code>&nbsp;<code>[0,1,1,0,1,0]</code>&nbsp;<code>[1,0,0,1,0,1]</code>&nbsp;<code>[1,0,0,1,1,0]</code>&nbsp;<code>[1,0,1,0,0,1]</code>&nbsp;<code>[1,0,1,0,1,0]</code>&nbsp;<code>[1,0,1,1,0,0]</code>&nbsp;<code>[1,1,0,0,1,0]</code>&nbsp;&nbsp;<code>[1,1,0,1,0,0]</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= zero, one, limit &lt;= 1000</code></li>
</ul>