You have a grid of size n x m and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).
Given n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 10^9 + 7.
Constraints -
m <= 6
n <= 5000
Example -
n = 1, m = 3
result = 12
n = 2, m = 3
result = 54
n = 5, m = 5
result = 580986
Similar to Number of Ways to Paint N × 3 Grid