Please help me on how to approach this problem with O(nk)

https://www.lintcode.com/problem/paint-house-ii/description