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)/用三种不同颜色为网格涂色 [painting-a-grid-with-three-different-colors].html
2022-03-29 12:43:11 +08:00

38 lines
1.4 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>m</code><code>n</code> 。构造一个 <code>m x n</code> 的网格,其中每个单元格最开始是白色。请你用 <strong>红、绿、蓝</strong> 三种颜色为每个单元格涂色。所有单元格都需要被涂色。</p>
<p>涂色方案需要满足:<strong>不存在相邻两个单元格颜色相同的情况</strong> 。返回网格涂色的方法数。因为答案可能非常大, 返回 <strong></strong><code>10<sup>9</sup> + 7</code><strong> 取余</strong> 的结果。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/colorthegrid.png" style="width: 200px; height: 50px;" />
<pre>
<strong>输入:</strong>m = 1, n = 1
<strong>输出:</strong>3
<strong>解释:</strong>如上图所示,存在三种可能的涂色方案。
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/copy-of-colorthegrid.png" style="width: 321px; height: 121px;" />
<pre>
<strong>输入:</strong>m = 1, n = 2
<strong>输出:</strong>6
<strong>解释:</strong>如上图所示,存在六种可能的涂色方案。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>m = 5, n = 5
<strong>输出:</strong>580986
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= m <= 5</code></li>
<li><code>1 <= n <= 1000</code></li>
</ul>