๋ฐฑ์ค 2210 ์ซ์ํ๊ด๋ฆฌ ํ์ด์ฌ
2022. 12. 29. 00:16ใ๐ฑ Algorithm/BFS DFS
dfs ํผ ๋ฏธ์ณค๋ค
result = set()
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
res = [list(map(str, input().split())) for _ in range(5)]
def dfs(r_, c_, tmp):
if len(tmp) == 6:
result.add(tmp)
return
for i in range(4):
nx = c_ + dx[i]
ny = r_ + dy[i]
if 0 <= ny < 5 and 0 <= nx < 5:
dfs(ny, nx, tmp + res[ny][nx])
for r in range(5):
for c in range(5):
dfs(r, c, res[r][c])
print(len(result))
'๐ฑ Algorithm > BFS DFS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค ์ ํ ์ ํ 11060 ํ์ด์ฌ (0) | 2022.03.11 |
---|---|
๋ฐฑ์ค 7569 ํ์ด์ฌ (0) | 2022.01.26 |