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)/切披萨的方案数 [number-of-ways-of-cutting-a-pizza].html
2022-03-29 12:43:11 +08:00

41 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>rows x cols</code>&nbsp;大小的矩形披萨和一个整数 <code>k</code>&nbsp;,矩形包含两种字符:&nbsp;<code>&#39;A&#39;</code> (表示苹果)和&nbsp;<code>&#39;.&#39;</code>&nbsp;(表示空白格子)。你需要切披萨 <code>k-1</code> 次,得到&nbsp;<code>k</code>&nbsp;块披萨并送给别人。</p>
<p>切披萨的每一刀,先要选择是向垂直还是水平方向切,再在矩形的边界上选一个切的位置,将披萨一分为二。如果垂直地切披萨,那么需要把左边的部分送给一个人,如果水平地切,那么需要把上面的部分送给一个人。在切完最后一刀后,需要把剩下来的一块送给最后一个人。</p>
<p>请你返回确保每一块披萨包含&nbsp;<strong>至少</strong>&nbsp;一个苹果的切披萨方案数。由于答案可能是个很大的数字,请你返回它对 10^9 + 7 取余的结果。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/05/10/ways_to_cut_apple_1.png" style="height: 378px; width: 500px;"></strong></p>
<pre><strong>输入:</strong>pizza = [&quot;A..&quot;,&quot;AAA&quot;,&quot;...&quot;], k = 3
<strong>输出:</strong>3
<strong>解释:</strong>上图展示了三种切披萨的方案。注意每一块披萨都至少包含一个苹果。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>pizza = [&quot;A..&quot;,&quot;AA.&quot;,&quot;...&quot;], k = 3
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>pizza = [&quot;A..&quot;,&quot;A..&quot;,&quot;...&quot;], k = 1
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= rows, cols &lt;= 50</code></li>
<li><code>rows ==&nbsp;pizza.length</code></li>
<li><code>cols ==&nbsp;pizza[i].length</code></li>
<li><code>1 &lt;= k &lt;= 10</code></li>
<li><code>pizza</code>&nbsp;只包含字符&nbsp;<code>&#39;A&#39;</code>&nbsp;&nbsp;<code>&#39;.&#39;</code>&nbsp;</li>
</ul>