Class Solution
- java.lang.Object
-
- g1901_2000.s1931_painting_a_grid_with_three_different_colors.Solution
-
public class Solution extends Object
1931 - Painting a Grid With Three Different Colors.Hard
You are given two integers
mandn. Consider anm x ngrid where each cell is initially white. You can paint each cell red , green , or blue. All cells must be painted.Return the number of ways to color the grid with no two adjacent cells having the same color. Since the answer can be very large, return it modulo
109 + 7.Example 1:

Input: m = 1, n = 1
Output: 3
Explanation: The three possible colorings are shown in the image above.
Example 2:

Input: m = 1, n = 2
Output: 6
Explanation: The six possible colorings are shown in the image above.
Example 3:
Input: m = 5, n = 5
Output: 580986
Constraints:
1 <= m <= 51 <= n <= 1000
-
-
Field Summary
Fields Modifier and Type Field Description static intP
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcolorTheGrid(int m, int n)
-
-
-
Field Detail
-
P
public static final int P
- See Also:
- Constant Field Values
-
-