CT048

House Painting Cost

HardAcceptance: 0.0%

A builder wants to build a row of n houses that can be of k different colors. No two neighboring houses can be the same color. Given an n by k matrix where entry [i][j] is the cost to build house i with color j, return the minimum cost. Input: first line n and k, then n lines each with k costs. Output: minimum cost.

Example 1:

Input: 3 3 1 2 3 4 5 6 7 8 9
Output: 13

Example 2:

Input: 2 3 1 2 3 4 5 6
Output: 5

Constraints:

1 <= n <= 100 1 <= k <= 100 1 <= cost <= 10^4

Tags:

dynamic-programming
Loading...
Test Cases:No test cases
No test cases available.