[python] 17472. 다리 만들기 2
문제 출처 17472. 다리 만들기 2 풀이 from collections import deque N, M = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(N)] visited = [[0]*M for _ in range(N)] dx, dy = (1, 0, -1, 0), (0, 1, 0, -1) def numbering_irlands(x, y): visited[y][x] = 1 arr[y][x] = irland q = deque() q.append((x, y)) while q: x, y = q.popleft() for i in range(4): nx, ny = x + dx[i], y + dy[i] if nx ..
2019. 10. 19.
[python] 단어 변환
문제 출처 단어 변환 풀이 def dfs(now, target, words, history=[], depth=0): global min_ print(now, history) if now == target: min_ = min(min_, depth) if depth >= min_: return for word in words: if word in history: continue cnt = 0 for i in range(len(target)): if word[i] != now[i]: cnt += 1 if cnt > 1: break if cnt == 1 and word not in history: history.append(word) dfs(word, target, words, history, depth+1)..
2019. 9. 1.