I came across below problem
There are N houses in a row. Each house can be painted in either Red, Green or Blue color. The cost of colouring each house in each of the colours is different. Find the colour of each house such that no two adjacent houses have the same colour and the total cost of colouring all the houses is minimum.
Here is the complete question
The problem to me looks bit confusing, as objective is to minmize the cost and ensure that no adjacent house have same colour. In that case should not i select the just two colours out of three whose cost is minimum.
Say here is the cost of colours
- Red $100
- Green $200
- Blue $300
I have 5 row houses to paint
Here will be my Algo
- Select Red and Green colour as their cost is minimum
calculate 5%2.
If 5%2 == 1 then start from last and select the colour of last house as Red($100). Now choose the alternate colour
If 5%2 == 0 then start from beginning and choose the alternate colour
I see Is "house coloring with three colors" NP? suggested the dynamic programming But i am not sure what is wrong with my approach and why dynamic programming is required here ?
no two adjacent houses have the same colour and the total cost of colouring all the houses is minimum.
so even if author intended a cost for each house-color combination, minimum cost will be what i explained in my algo. Here is the full question careercup.com/question?id=9941005 – user3198603