Skip to content

Commit d056690

Browse files
author
windsor
committed
[boj]알파벳
1 parent 5a243c4 commit d056690

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

BOJ/1987.알파벳/6047198844.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#y,x좌표에서 중복없이 갈수있는 최대의 수.
2+
from functools import lru_cache
3+
4+
R, C = map(int, input().split())
5+
board = [list(input())for _ in range(R)]
6+
path = set()
7+
8+
9+
def dfs(y, x):
10+
res = 1
11+
path.add(board[y][x])
12+
for dy, dx in (-1,0), (1,0), (0,-1), (0,1):
13+
ny = y + dy
14+
nx = x + dx
15+
if 0 <= ny < R and 0 <= nx < C and board[ny][nx] not in path:
16+
res = max(res, 1 + dfs(ny, nx))
17+
path.remove(board[y][x])
18+
return res
19+
20+
print(dfs(0, 0))

0 commit comments

Comments
 (0)