-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
섹션 7 미로탐색 문제 왜 체크함수로 풀면 오답이나오나요?
21.11.16 21:24 작성 조회수 121
0
import sys from collections import deque #sys.stdin=open("input.txt", "r") dx=[-1, 0, 1, 0] dy=[0, 1, 0, -1] def DFS(x, y): global cnt if x==6 and y==6: cnt+=1 else: for i in range(4): xx=x+dx[i] yy=y+dy[i] if 0<=xx<=6 and 0<=yy<=6 and board[xx][yy]==0: board[xx][yy]=1 DFS(xx, yy) board[xx][yy]=0 if __name__=="__main__": board=[list(map(int, input().split())) for _ in range(7)] cnt=0 board[0][0]=1 DFS(0, 0) print(cnt)우
위에가 실제 정답이고,
import sys
from collections import deque
#sys.stdin=open("input.txt", "r")
dx=[-1, 0, 1, 0]
dy=[0, 1, 0, -1]
def DFS(x, y):
global cnt
if x==6 and y==6:
cnt+=1
else:
for i in range(4):
xx=x+dx[i]
yy=y+dy[i]
if 0<=xx<=6 and 0<=yy<=6 and board[xx][yy]==0 and ch[xx][yy]==0:
ch[xx][yy]=1
DFS(xx, yy)
ch[xx][yy]=0
if __name__=="__main__":
board=[list(map(int, input().split())) for _ in range(7)]
ch=[[0]*8]*8
cnt=0
board[0][0]=1
DFS(0, 0)
print(cnt)
왜 다음과 같이 체크리스트를 포함하면 답이 안나오고, 0만 나올까요??
왜 저렇게 풀면 안되는지 알고싶어요!
답변을 작성해보세요.
답변 0