pypy 제출
def dfs(p, x, y):
global result
if x == N-1 and y == N-1:
result += 1
return
else:
if p == 1:
if x <= N-1 and y+1 <= N-1 and H[x][y+1] == 0:
dfs(1, x, y+1)
if x+1 <= N-1 and y+1 <= N-1 and H[x+1][y] == 0 and H[x][y+1] == 0 and H[x+1][y+1] == 0:
dfs(3, x+1, y+1)
elif p == 2:
if x+1 <= N-1 and y <= N-1 and H[x+1][y] == 0:
dfs(2, x+1, y)
if x+1 <= N-1 and y+1 <= N-1 and H[x+1][y] == 0 and H[x][y+1] == 0 and H[x+1][y+1] == 0:
dfs(3, x+1, y+1)
elif p == 3:
if x <= N-1 and y+1 <= N-1 and H[x][y+1] == 0:
dfs(1, x, y+1)
if x+1 <= N-1 and y <= N-1 and H[x+1][y] == 0:
dfs(2, x+1, y)
if x+1 <= N-1 and y+1 <= N-1 and H[x+1][y] == 0 and H[x][y+1] == 0 and H[x+1][y+1] == 0:
dfs(3, x+1, y+1)
N = int(input())
H = [list(map(int, input().split(' '))) for _ in range(N)]
result = 0
dfs(1, 0, 1)
print(result)
'알고리즘 > 백준 (Pyhthon)' 카테고리의 다른 글
[알고리즘] 백준 15653 구슬 탈출 4 / 파이썬 (0) | 2020.09.17 |
---|---|
[알고리즘] 백준 16918 봄버맨 / 파이썬 (0) | 2020.09.15 |
[알고리즘] 백준 14499 주사위 굴리기 / 파이썬 (0) | 2020.09.15 |
[알고리즘] 백준 16500 문자열 판별 / python (0) | 2020.09.15 |
[알고리즘] 백준 16637 괄호 추가하기 / python (0) | 2020.09.10 |