Paint House III

There is a row of m houses in a small city, each house must be painted with one of the n colors. Some houses are already painted — houses[i] is the color of house i (0 means unpainted).

A neighborhood is a maximal group of consecutive houses with the same color. You want exactly target neighborhoods.

Return the minimum cost to paint all houses to achieve exactly target neighborhoods. Return -1 if it is not possible.

Colors are 1-indexed (1 to n). Cost to paint house i with color j is cost[i][j-1].

Examples
Input: [[0,0,0,0,0],[[1,10],[10,1],[10,1],[1,10],[5,1]],5,2,3]
Output: 9
Hints

Paint House III

There is a row of `m` houses in a small city, each house must be painted with one of the `n` colors. Some houses are already painted — `houses[i]` is the color of house `i` (0 means unpainted).