백준 1987 알파벳 - bfs
""" 백준 1987 알파벳 """ import sys input = sys.stdin.readline R, C = map(int, input().split()) arr = [input() for _ in range(R)] dir = [[0, 1], [0, -1], [1, 0], [-1, 0]] q = set([(0, 0, arr[0][0])]) answer = 1 while q : y, x, v = q.pop() for d in dir: ny = y + d[0] nx = x + d[1] if 0
더보기
블록이동하기(드론 조종) - bfs
def solution(board): H = len(board) W = len(board[0]) moves = [ [0, 1], [0, -1], [1, 0], [-1, 0] ] def bfs(): state = [[[True, True] for _ in range(W)] for __ in range(H)] # 0 가로, 1 세로 q = [[0, 0, 0, 0]] state[0][0][0] = False while q: y, x, curDir, cnt = q.pop(0) if curDir: # 탈출 조건 체크 if x == W - 1 and y + 1 == H - 1: return cnt # 현재 세로라면 이동 or 회전 4가지 # 이동한다면 for move in moves: # 갈 수 있는지 이제부터 확..
더보기