2
public int minDistance(int[] houses, int k) {8
i++) { // know optimal dist for i-1, then for i, we add houses[i] - houses[i/2]9
dp[i] = dp[i - 1] + houses[i] - houses[i / 2];11
for (int i = 0; i < k - 1; i++) {12
int[] next = new int[n];13
Arrays.fill(next, Integer.MAX_VALUE);14
for (int j = 0; j < n; j++) {16
for (int m = j; m >= 0; m--) {18
houses[(m + j + 1) >> 1]19
- houses[m]; // likewise, adding to the front needs the +1 to account for the21
next[j] = Math.min(next[j], (m == 0 ? 0 : dp[m - 1]) + sum);