-
[백준] 12869 - 뮤탈리스크 (파이썬)알고리즘/백준 2021. 9. 23. 16:28
n = int(input()) array = list(map(int,input().split())) array.sort(reverse=True) check = [-9,-3,-1] visit = [0,0,0] cnt = 99999999999 def DFS(a,b,c,v): global cnt if a<=0 and b<=0 and c<=0: cnt = min(cnt,v) return a1 = a-9 b1 = b-3 c1 = c-1 t = [a1,b1,c1] t.sort(reverse=True) DFS(t[0],t[1],t[2],v+1) a2 = a-9 b2 = b-1 c2 = c-3 tt = [a2,b2,c2] tt.sort(reverse=True) DFS(tt[0],tt[1],tt[2],v+1) a2 = a-3 b2 = b-9 c2 = c-1 tt = [a2,b2,c2] tt.sort(reverse=True) DFS(tt[0],tt[1],tt[2],v+1) def DFS2(a,b,v): global cnt if a<=0 and b<=0: cnt = min(cnt,v) return a1 = a-9 b1 = b-3 t = [a1,b1] t.sort(reverse=True) DFS2(t[0],t[1],v+1) a2 = a-3 b2 = b-9 tt = [a2,b2] tt.sort(reverse=True) DFS2(tt[0],tt[1],v+1) if n==3: DFS(array[0],array[1],array[2],0) print(cnt) elif n==2: DFS2(array[0],array[1],0) print(cnt) else: if array[0]%9 == 0: print(array[0]//9) else: print(array[0]//9+1)
SCV 개수에 따라서 다른 함수를 적용했는데 완전 구린코드..
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 12970 - AB (파이썬) (0) 2021.09.24 [백준] 12904 - A와 B (파이썬) (0) 2021.09.23 [백준] 12738 - 가장 긴 증가하는 부분 수열 3 (파이썬) (0) 2021.09.23 [백준] 11659 - 구간 합 구하기 4 (파이썬) (0) 2021.09.23 [백준] 11066 - 파일 합치기 (파이썬) (0) 2021.09.23