Paint House
Recognize the pattern
Brute force idea
The naive version of Paint House sounds like this: Try all color assignments. Each house has k choices, exponential total. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.
Better approach
A calmer way to see Paint House is this: DP: dp[i][c] = min cost to paint houses 0.i where house i is color c. dp[i][c] = cost[i][c] + min(dp[i-1][not c]). For 3 colors, just check the other two., optimizable to by tracking the two smallest. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
Key invariant
The truth you want to protect throughout Paint House is this: The optimal color for house i depends only on which color was cheapest for house i-1 EXCLUDING the same color. Tracking the two cheapest previous costs lets you decide in per color. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Watch out for
A common way to get lost in Paint House is this: Only tracking the single cheapest previous color — when the current house would use the same cheapest color, you need the second cheapest as a fallback. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.