[20251206] BOJ / G4 / 우유 도시 / 이강현 #1598
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/14722
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
우유는 딸기,초코,바나나순으로만 마실 수 있음.
NxN의 격자무늬의 지도에서 각 칸들은 우유를 한종류만 팜
이때 (1,1)부터 (N,N)까지 가는데, 우유를 최대한 많이 마실때 그 개수를 출력.
🔍 풀이 방법
dp
0일때를 초기화하고 첫행, 첫열을 초기화한 후,
(2,2)부터 위와 왼쪽에서 오는 값을 비교해서 구했다.
⏳ 회고
직접 구현하니까 코드가 복잡했는데, 잘짠 코드를 둘러보다 기발한 아이디어를 발견했다.
무조건 딸기,초코,바나나순서로 먹어야하므로 우유의 종류를 따로 저장하지 않는다는 것.
즉, 현재까지 먹은 개수가 0이면 딸기를 먹어야하고 1이면 초코, 2면 바나나 3이면 다시 딸기를 먹어야 한다.
따라서 나머지 연산을 통해 간단하게 구현할 수 있었다.