Class Solution
java.lang.Object
g1901_2000.s1931_painting_a_grid_with_three_different_colors.Solution
1931 - Painting a Grid With Three Different Colors.<p>Hard</p>
<p>You are given two integers <code>m</code> and <code>n</code>. Consider an <code>m x n</code> grid where each cell is initially white. You can paint each cell <strong>red</strong> , <strong>green</strong> , or <strong>blue</strong>. All cells <strong>must</strong> be painted.</p>
<p>Return <em>the number of ways to color the grid with <strong>no two adjacent cells having the same color</strong></em>. Since the answer can be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/06/22/colorthegrid.png" alt="" /></p>
<p><strong>Input:</strong> m = 1, n = 1</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> The three possible colorings are shown in the image above.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/06/22/copy-of-colorthegrid.png" alt="" /></p>
<p><strong>Input:</strong> m = 1, n = 2</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The six possible colorings are shown in the image above.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> m = 5, n = 5</p>
<p><strong>Output:</strong> 580986</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= m <= 5</code></li>
<li><code>1 <= n <= 1000</code></li>
</ul>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
P
public static final int P- See Also:
-
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
colorTheGrid
public int colorTheGrid(int m, int n)
-