The key to this problem lies in understanding the principles.
Let me explain the algorithm to solve the problem by using DP.
First, you need the same storage space like input data's size.
When you draw any color of the nth house, the space will contain the minimum value.
If you paint the red in the second house, this value is sum of blue or green of the first house.
You must use DP because you must use the previous value.
Of course, you can also use the recursive algorithm to solve it. But if it gets bigger, it will take a lot of time.
If you paint the red in the nth house in the same way, you should add the lower value of the blue and green of the n-1th house.
Therefore, the minimum value can be found in the value of the storage space (n-1) index.
<pesudo code>

댓글
댓글 쓰기