1931. Painting a Grid With Three Different Colors Hard
1/**
2 * [1931] Painting a Grid With Three Different Colors
3 *
4 * You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted.
5 * 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 10^9 + 7.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/colorthegrid.png" style="width: 200px; height: 50px;" />
9 * Input: m = 1, n = 1
10 * Output: 3
11 * Explanation: The three possible colorings are shown in the image above.
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/22/copy-of-colorthegrid.png" style="width: 321px; height: 121px;" />
15 * Input: m = 1, n = 2
16 * Output: 6
17 * Explanation: The six possible colorings are shown in the image above.
18 *
19 * Example 3:
20 *
21 * Input: m = 5, n = 5
22 * Output: 580986
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= m <= 5
28 * 1 <= n <= 1000
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/painting-a-grid-with-three-different-colors/
34// discuss: https://leetcode.com/problems/painting-a-grid-with-three-different-colors/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn color_the_grid(m: i32, n: i32) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_1931() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.