취준시절/백준

[백준 2210] 숫자판 점프 - Python

MAYMIN 2021. 7. 1. 18:28
728x90
SMALL
direction = [(1,0),(-1,0),(0,1),(0,-1)]

def dfs(x,y,num):
    if len(num) == 6:
        if num not in answer:
            answer.append(num)
        return

    for i in range(len(direction)):
        dx = x + direction[i][0]
        dy = y + direction[i][1]

        if 0<= dx <5 and 0<= dy < 5:
            dfs(dx,dy,graph[dx][dy]+num)


graph = []
for i in range(5):
    graph.append(list(map(str,input().split())))

answer = []

for i in range(5):
    for j in range(5):
        dfs(i,j,graph[i][j])

print(len(answer))
728x90
LIST