> For the complete documentation index, see [llms.txt](https://shangan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shangan.gitbook.io/algorithm/he-xin-suan-fa-200-ti/basic-dynamic-programming-and-coordinate-dynamic-programming/coordinate-dynamic-programming/paint-house.md).

# Paint House

{% tabs %}
{% tab title="Java" %}

```java
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]
				}
			}
		}
}

```

{% endtab %}
{% endtabs %}
