문제 링크: 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 |