[20250410] BOJ / P2 / 최대 문자열 붙여넣기 / 권혁준 #307
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/2401
🧭 풀이 시간
17분
👀 체감 난이도
✏️ 문제 설명
어떤 긴 문자열이 주어지고 여러 개의 짧은 문자열들이 주어질 때 이때 짧은 문자열을 긴 문자열에 붙여 넣을때 가장 길게 붙여 넣는 경우를 찾아라.
단 이때 짧은 문자열들끼리는 교차 할 수 없다. (‘aabbc' 에 'aab' 와 'bbc' 둘 다 붙여 넣는 것은 불가능하다.) 또, 짧은 문자열은 여러 번 사용할 수 있다.
🔍 풀이 방법
[사용한 알고리즘]
짧은 문자열 각각에 대해 부분 일치 테이블을 구했다.
dp[i] = 긴 문자열의 i번째 글자까지 확인했을 때 문제의 정답으로 정의하고,긴 문자열에서 한 문자씩 보면서 모든 작은 문자열과의 매칭 여부를 확인한다.
매칭된 것이 있다면, dp값을 갱신해준다.
⏳ 회고
코드트리에 있던 문제와 똑같다 (https://www.codetree.ai/ko/trails/complete/curated-cards/challenge-padding-a-string/description)