목록Algorithm/Ch 4. 응용 알고리즘 (2)
토니의 연습장
https://www.acmicpc.net/problem/2252from collections import dequeN, M = list(map(int, input().split()))adj = [[] for _ in range(N)]need_to_learn = [0]*Nfor _ in range(M): a,b = list(map(int, input().split())) adj[a-1].append(b-1) need_to_learn[b-1] += 1 # 위상 정렬queue = deque([]) # 처리 가능 목록for i in range(N): if need_to_learn[i] == 0: queue.append(i) # 리스트에 쌓아두고 하나씩 처리 위함 ..
https://www.acmicpc.net/problem/1463N = int(input())a = [0]*(N+1) # 길이 N+1, a[N] 참조 가능a[1] = 0for i in range(2, N+1): a[i] = 1+a[i-1] if i%3 == 0: a[i] = min(a[i], 1+a[i//3]) if i%2 == 0: a[i] = min(a[i], 1+a[i//2]) print(a[N]) https://www.acmicpc.net/problem/2579N = int(input())S = [0]*Nfor i in range(N): S[i] = int(input())A = [0]*NB = [0]*NA[0] = S[0]B[0] ..