doctscoder
하고싶은일있는개발
doctscoder
전체 방문자
오늘
어제
  • 분류 전체보기 (305)
    • 코테용 문제풀이 (304)
      • 백준 (272)
      • 알고스팟 (32)
    • 공부계획 (1)

최근 글

hELLO · Designed By 정상우.
doctscoder

하고싶은일있는개발

코테용 문제풀이/백준

알파벳 풀이

2023. 2. 22. 21:24

문제 링크: https://www.acmicpc.net/problem/1987

백준 알고리즘 중급 1/3 531에서 12번째 - 1987번 알파벳을 풀어보았다.

 

풀이: https://campkim.tistory.com/18

 

C++

 

Python

import sys

R, C = map(int, sys.stdin.readline().split())
board = [list(sys.stdin.readline().strip()) for _ in range(R)]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
answer = 1
def BFS(x, y):
    global answer
    q = set([(x, y, board[x][y])])
    while q:
        x, y, ans = q.pop()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if ((0 <= nx < R) and (0 <= ny < C)) and (board[nx][ny] not in ans):
                q.add((nx,ny,ans + board[nx][ny]))
                answer = max(answer, len(ans)+1)

BFS(0, 0)
print(answer)

Java

 

저작자표시 비영리 변경금지 (새창열림)

'코테용 문제풀이 > 백준' 카테고리의 다른 글

구슬 탈출 2 풀이  (0) 2023.02.22
가르침 풀이  (0) 2023.02.22
스도미노쿠 풀이  (1) 2023.02.22
스도쿠 풀이  (0) 2023.02.22
N-Queen 풀이  (0) 2023.02.22
    '코테용 문제풀이/백준' 카테고리의 다른 글
    • 구슬 탈출 2 풀이
    • 가르침 풀이
    • 스도미노쿠 풀이
    • 스도쿠 풀이
    doctscoder
    doctscoder
    코딩 관련 공부를 적어놓는 블로그

    티스토리툴바