[20250814] BOJ / G4 / 가르침 / 이강현 #664
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/1062
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
알파벳 소문자로 이루어진 단어들과 가르칠 수 있는 글자 수가 주어졌을때, 최대한 많은 단어들을 읽을 수 있게 글자를 가르쳤을때, 읽을 수 있는 단어 수를 출력.
🔍 풀이 방법
백트래킹
가르친 글자를 나타내는 배열
가르쳐야할 글자를 나타내는 배열
가르쳐야하는 글자 수
이 세개를 저장해서 조건에 맞게 백트래킹 진행
⏳ 회고
가르쳐야하는 글자가 K보다 작다면 모두 가르칠 수 있고 이 종료조건을 걸게 되면
백트래킹에서의 종료조건에 depth == K를 사용할 수 있음.
이 조건을 달지 않으면 백트래킹에서 K가 너무 클때 종료조건에 닿지 않는 경우가 생겼음.
이건 무조건 알파벳 처음부터 탐색하도록 했다면 문제가 생기지 않을 것 같긴 한데, 내 코드의 경우에는 백트래킹의 depth를 최대한 낮추기 위해 가르치지 않아도 되는 부분을 최대한 건너뛴 후 진행하는 방식을 택했기 때문에 이런 반례가 나왔던 것 같음.