260119 : [BOJ 1029] 그림 교환 #2317
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.
🚀 이슈 번호
Resolve: {#2314}
🧩 문제 해결
스스로 해결: ❌
🔎 접근 과정
완전탐색을 하기에는 시간초과 문제가 있음
사람당 한번씩만 그림을 살 수 있고 왔던 경로와 현재 위치에 따라 다음 그림 구매의 가격이 정해지기 때문에, 외판원 순회처럼 풀 수 있겠다고 생각했음.
dp[route|mask][n] > cost[prev].charAt(n) - '0' 이부분을 동일 할때도 탐색을 진행하면 시간 초과가 남.
⏱️ 시간 복잡도
O(2^N * N^2)경로 개수가 2^N개, 경로별로 마지막 위치가 N개로 총 2^N * N 개의 상태가 존재
각 상태 별로 N개의 다음 이동경로를 탐색함.
💻 구현 코드