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)/给 N x 3 网格图涂色的方案数 [number-of-ways-to-paint-n-3-grid].html

50 lines
1.5 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>你有一个 <code>n x 3</code>&nbsp;的网格图 <code>grid</code>&nbsp;,你需要用 <strong>红,黄,绿</strong>&nbsp;三种颜色之一给每一个格子上色,且确保相邻格子颜色不同(也就是有相同水平边或者垂直边的格子颜色不同)。</p>
<p>给你网格图的行数 <code>n</code>&nbsp;</p>
<p>请你返回给&nbsp;<code>grid</code>&nbsp;涂色的方案数。由于答案可能会非常大,请你返回答案对&nbsp;<code>10^9 + 7</code>&nbsp;取余的结果。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>n = 1
<strong>输出:</strong>12
<strong>解释:</strong>总共有 12 种可行的方法:
<img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/04/12/e1.png" style="height: 289px; width: 450px;">
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>n = 2
<strong>输出:</strong>54
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>n = 3
<strong>输出:</strong>246
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>n = 7
<strong>输出:</strong>106494
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>n = 5000
<strong>输出:</strong>30228214
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == grid.length</code></li>
<li><code>grid[i].length == 3</code></li>
<li><code>1 &lt;= n &lt;= 5000</code></li>
</ul>