mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>你有一个 <code>n x 3</code> 的网格图 <code>grid</code> ,你需要用 <strong>红,黄,绿</strong> 三种颜色之一给每一个格子上色,且确保相邻格子颜色不同(也就是有相同水平边或者垂直边的格子颜色不同)。</p>\n\n<p>给你网格图的行数 <code>n</code> 。</p>\n\n<p>请你返回给 <code>grid</code> 涂色的方案数。由于答案可能会非常大,请你返回答案对 <code>10^9 + 7</code> 取余的结果。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>n = 1\n<strong>输出:</strong>12\n<strong>解释:</strong>总共有 12 种可行的方法:\n<img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/04/12/e1.png\" style=\"height: 289px; width: 450px;\">\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>n = 2\n<strong>输出:</strong>54\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>n = 3\n<strong>输出:</strong>246\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre><strong>输入:</strong>n = 7\n<strong>输出:</strong>106494\n</pre>\n\n<p><strong>示例 5:</strong></p>\n\n<pre><strong>输入:</strong>n = 5000\n<strong>输出:</strong>30228214\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == grid.length</code></li>\n\t<li><code>grid[i].length == 3</code></li>\n\t<li><code>1 <= n <= 5000</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 103,
|
||||
"likes": 104,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -137,7 +137,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"8.5K\", \"totalSubmission\": \"15.3K\", \"totalAcceptedRaw\": 8528, \"totalSubmissionRaw\": 15325, \"acRate\": \"55.6%\"}",
|
||||
"stats": "{\"totalAccepted\": \"8.6K\", \"totalSubmission\": \"15.5K\", \"totalAcceptedRaw\": 8632, \"totalSubmissionRaw\": 15515, \"acRate\": \"55.6%\"}",
|
||||
"hints": [
|
||||
"We will use Dynamic programming approach. we will try all possible configuration.",
|
||||
"Let dp[idx][prev1col][prev2col][prev3col] be the number of ways to color the rows of the grid from idx to n-1 keeping in mind that the previous row (idx - 1) has colors prev1col, prev2col and prev3col. Build the dp array to get the answer."
|
||||
|
Reference in New Issue
Block a user