[20251028] PGM / LV3 / N으로 표현 / 강신지 #1253
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://school.programmers.co.kr/learn/courses/30/lessons/42895
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
숫자 N과 number가 주어질 때, N과 사칙연산만 사용해서 표현 할 수 있는 방법 중 N 사용횟수의 최솟값을 구하라.
ex. N=5, number=12일 때 N 사용 횟수의 최솟값은 4
12 = (55 + 5) / 5 이므로.
🔍 풀이 방법
N을 1개부터 8개까지 사용해 만들 수 있는 모든 수의 조합을 Set에 저장하며 탐색했다.
각 단계에서 이전에 만든 수들을 사칙연산으로 조합해 새로운 수를 만들고,
그중 목표값 number가 나오면 해당 사용 횟수를 반환했다.
8개까지 써도 안나오면 -1 리턴.
⏳ 회고
dp인 건 알겠는데 숫자 n개로 만들 수 있는 수를 저장해두는 생각을 하는 데에 오래 걸렸다