λ¬Έμ
https://www.acmicpc.net/problem/2210
νμ΄
# λ°±μ€ 2210λ² λ¬Έμ - μ«μν μ ν
from collections import deque
dx, dy = [0,0,-1,1], [1,-1,0,0]
graph = [list(map(str, input().split(' '))) for _ in range(5)]
def dfs(x, y, number):
if len(number) == 6:
if number not in result:
result.append(number)
return
q = deque()
q.append((x,y))
while q:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<=nx<5 and 0<=ny<5:
dfs(nx, ny, number + graph[nx][ny])
result = []
for i in range(5):
for j in range(5):
dfs(i, j, graph[i][j])
print(len(result))
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] 17086λ²_μκΈ° μμ΄ 2 (0) | 2022.12.02 |
---|---|
π© [λ°±μ€] [Python] 11060λ²_μ ν μ ν (0) | 2022.11.28 |
π© [λ°±μ€] [Python] 5567λ²_κ²°νΌμ (0) | 2022.11.28 |
π© [λ°±μ€] [Python] 11055λ²_κ°μ₯ ν° μ¦κ° λΆλΆ μμ΄ (0) | 2022.11.28 |
π© [λ°±μ€] [Python] 17413λ²_λ¨μ΄ λ€μ§κΈ° 2 (1) | 2022.11.28 |