> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/dynamic-programming/rgb-street.md).

# RGB Street

내 접근 방법 : 1차원 DP

d\[n] = n개의 집 색칠 최소 비용\
\=> n번째 집 색이 0인지, 1인지, 2인지에 따라 최솟값을 구하면 정답이 된다!\
d\[n] = Math.min(d\[n-1]+P\[0] , d\[n-1]+P\[1] , d\[n-1]+P\[2])

정답 찾는 접근 방법은 맞았다!\
그런데 정답에는 2차원 DP를 정의해서 n번째 집의 색을 함께 기록해주었다!\
**d\[n] = Math.min(d\[n]\[0], d\[n]\[1], d\[n]\[2])**\
**d\[n]\[0] = Math.min(d\[n-1]\[1],d\[n-1]\[2]) + P\[n]\[0]**\
**d\[n]\[1] = Math.min(d\[n-1]\[0],d\[n-1]\[2]) + P\[n]\[1]**\
**d\[n]\[2] = Math.min(d\[n-1]\[0],d\[n-1]\[1]) + P\[n]\[2]**

여기서 d\[n-1]이라고 단순히 계산했는데, 사실 n번째 집 색이 0 이라면 n-1은 1 또는 2 중 최솟값이 된다!!!\
마찬가지로 n=1 ) n-1 = 0 또는 2 중 최솟값\
마찬가지로 n=2 ) n-1 = 0 또는 1 중 최솟값

**n-1**과 **n-1 = 0 또는 1 중 최솟값**은 다르다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://heunnajo.gitbook.io/algorithms-problem-solving-skills/dynamic-programming/rgb-street.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
