# Paint House - Many Colors

#### Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

`1. You are given a number n and a number k separated by a space, representing the number of houses and number of colors.2. In the next n rows, you are given k space separated numbers representing the cost of painting nth house with one of the k colors.3. You are required to calculate and print the minimum cost of painting all houses without painting any consecutive house with same color.`
Input Format
`A number nn1-0th n1-1st n1-2nd .. n1-kthn2-0th n2-1st n2-2nd .. n2-kth.. n number of elements`
Output Format
`A number representing the minimum cost of painting all houses without painting any consecutive house with same color.`
Question Video
Constraints
`1 <= n <= 10001 <= k <= 100 <= n1-0th, n1-1st, .. <= 1000`
Sample Input
`4 31 5 75 8 43 2 91 2 4`
Sample Output
`8`

• Related Topics

Run

Run
Id Name