https://www.acmicpc.net/problem/14226
실패이유
: 구현실패
import collections
NOT_VISIT = 5000
s = int(input())
dist = [[NOT_VISIT] * 1001 for _ in range(1001)] # dist[현재 이모티콘 개수][클립보드의 이모티콘 개수] 를 나타내는 이차원 배열
queue = collections.deque([(1, 0)])
dist[1][0] = 0
while queue:
emo_cnt, clip_cnt = queue.popleft()
if dist[emo_cnt][emo_cnt] == NOT_VISIT: # 현재 이모티콘을 클립보드에 복사
dist[emo_cnt][emo_cnt] = dist[emo_cnt][clip_cnt] + 1
queue.append((emo_cnt, emo_cnt))
if emo_cnt + clip_cnt < 1001 and dist[emo_cnt + clip_cnt][clip_cnt] == NOT_VISIT: # 클립보드 붙여넣기
dist[emo_cnt + clip_cnt][clip_cnt] = dist[emo_cnt][clip_cnt] + 1
queue.append((emo_cnt + clip_cnt, clip_cnt))
if emo_cnt > 1 and dist[emo_cnt - 1][clip_cnt] == NOT_VISIT: # 현재 이모티콘에서 1개 삭제
dist[emo_cnt - 1][clip_cnt] = dist[emo_cnt][clip_cnt] + 1
queue.append((emo_cnt - 1, clip_cnt))
print(min(dist[s]))
dist
를 현재 이모티콘과 클립보드의 이모티콘 개수를 나타내는 2차원 배열로 선언- 방문하지 않은 경우에만
클립보드 복사
,클립보드 붙여넣기
,이모티콘 1개 삭제
와 같은 동작 수행
출처 : 코드플러스 - 알고리즘 기초 2/2 강의
https://code.plus/course/42