Search
⌘K

Leetcode 1931. Painting a Grid With Three Different Colors

Count the number of ways to color an m×n grid with 3 colors so that no two adjacent cells (horizontally or vertically) share a color; with m ≤ 5 and n ≤ 1000, the typical approach is to enumerate valid column colorings (state compression), build transitions between compatible columns, and perform DP or matrix exponentiation across n columns modulo 1e9+7.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.