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 = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
cnt = 0
DFS(0, 0)
print(cnt)
|
cs |
728x90
'Data Structures & Algorithms' 카테고리의 다른 글
[Algorithms] 깊이/넓이 우선 탐색 (DFS, BFS) 활용-안전 영역 (DFS, BFS 2가지 방법으로) (0) | 2022.06.05 |
---|---|
[Algorithms] 깊이/넓이 우선 탐색 (DFS, BFS) 활용-단지 번호 붙이기(DFS, BFS 2가지 방법으로) (0) | 2022.06.03 |
[Algorithms] 동적 계획법(Dynamic Programming)-네트워크 선 자르기(Bottom up) / (Top Down) 2가지 방식 (0) | 2022.05.30 |
[Algorithms] 동적 계획법(Dynamic Programming) 설명 (0) | 2022.05.30 |
[Algorithms] Basic 병합정렬 / 퀵정렬 (0) | 2022.05.29 |