Data Structures & Algorithms

[Algorithms] 깊이/넓이 우선 탐색 (DFS, BFS) 활용-미로탐색(DFS)

숄구-ml 2022. 6. 3. 13:50

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def DFS(x, y):
    global cnt
 
    if x==y==6:
        cnt+=1
 
    else:
        for i in range(4):
            x_ = x + dx[i]
            y_ = y + dy[i]
            if 0 <=x_<= 6 and 0<=y_<=6 and board[x_][y_]==0:
                board[x_][y_] = 1
                DFS(x_, y_)
                board[x_][y_]  = 0
 
 
if __name__=='__main__':
 
    board = [list(map(int, input().split())) for _ in range(7)]
    board[0][0= 1
 
    dx = [-1010]
    dy = [010-1]
 
    cnt = 0
    DFS(00)
    print(cnt)
cs
728x90