mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>你有一个 <code>n x 3</code> 的网格图 <code>grid</code> ,你需要用 <strong>红,黄,绿</strong> 三种颜色之一给每一个格子上色,且确保相邻格子颜色不同(也就是有相同水平边或者垂直边的格子颜色不同)。</p>
 | 
						||
 | 
						||
<p>给你网格图的行数 <code>n</code> 。</p>
 | 
						||
 | 
						||
<p>请你返回给 <code>grid</code> 涂色的方案数。由于答案可能会非常大,请你返回答案对 <code>10^9 + 7</code> 取余的结果。</p>
 | 
						||
 | 
						||
<p> </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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>n == grid.length</code></li>
 | 
						||
	<li><code>grid[i].length == 3</code></li>
 | 
						||
	<li><code>1 <= n <= 5000</code></li>
 | 
						||
</ul>
 |