Error:
first I get the equation: dp[i][j] = min(dp[i - 1][k]) + cost[i][j] (k != j)
, but it needs O(n * k * k), which loop for all n and for each n loop for all previous k for each current k in the n.
So it come up with second equation: dp[i][j] = dp[i - 1][j] + min_cost (j != index of cost) || dp[i][j] = dp[i - 1][j] + min_sec_cost (j = index of cost). Which cost is the first and second minimum.