Paint House
public class Solution {
/**
* @param costs: n x 3 cost matrix
* @return: An integer, the minimum cost to paint all houses
*/
public int minCost(int[][] costs) {
dp[0][0] = costs[0][0];
dp[0][1] = costs[0][1];
dp[0][2] = costs[0][2];
for (int i = 1; i < costs.length; i++) {
for (int j = 0; j < costs[0].length; i++) {
dp[i][j] = Math.min(costs[i - 1][(j + 1) % 3], costs[i - 1][(j + 2) % 3]) + costs[i][j]
}
}
}
}
最后更新于
这有帮助吗?