4
vector<vector<int>> c; // n8
int dfs(int idx, int prev, int curt) {9
if (curt < 1) return INT_MAX;10
if (idx == mm) return (curt == 1) ? 0 : INT_MAX;11
if (dp[idx][prev][curt] != -1) return dp[idx][prev][curt];15
for (int x = 0; x < nn; x++) {17
int rres = dfs(idx + 1, color, curt - (prev != 21 and prev != color));18
if (rres != INT_MAX) res = min(c[idx][color - 1] + rres, res);21
return dp[idx][prev][curt] = dfs(idx + 1, color, curt - (prev != 21 and prev != color));23
return dp[idx][prev][curt] = res;27
int minCost(vector<int> &houses, vector<vector<int>> &cost, int m, int n, int target) {28
h = houses, c = cost, mm = m, nn = n, t = target;29
memset(dp, -1, sizeof(dp));30
int res = dfs(0, 21, t);31
return res == INT_MAX ? -1 : res;