Home

[백준] 토마토

문제 from collections import deque n, m = map(int, input().split()) box = [list(map(int, input().split())) for _ in range(m)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] queue = deque() for j in range(m): for i in range(n): if box[j][i] == 1: queue.append((i, j, 0)) max_days = 0 while queue: x, y, day = queue.popleft(...

Read more

[백준] 회의실 배정

문제 n = int(input()) time = [list(map(int, input().split())) for _ in range(n)] time.sort(key=lambda x: (x[1], x[0])) cnt = 0 end_time = 0 for start, end in time: if start >= end_time: end_time = end cnt += 1 print(cnt)

Read more

[백준] A와 B2

문제 s = input() t = input() def func(t, s): if t == s: return 1 if len(t) <= len(s): return 0 if t[-1] == 'A': if func(t[:-1], s): return 1 if t[0] == 'B': if func(t[::-1][:-1], s): return 1 return 0 print(func(t, s))

Read more

[백준] 하노이의 탑

문제 n = int(input()) print(2**n - 1) def hanoi(n, st, aux, to): if n == 1: print(f'{st} {to}') return hanoi(n-1, st, to, aux) print(f'{st} {to}') hanoi(n-1, aux, st, to) hanoi(n, '1', '2', '3')

Read more

[백준] 평범한 배낭

문제 n, k = map(int, input().split()) items = [] for _ in range(n): w, v = map(int, input().split()) items.append((w, v)) bag = [0] * (k + 1) for w, v in items: for i in range(k, w - 1, -1): bag[i] = max(bag[i], bag[i - w] + v) print(bag[k])

Read more