[처음]
from sys import stdin
from itertools import combinations as cb
def solution(round):
global ans
if round == 15:
ans = 1
for sub in res:
if sub.count(0) != 3:
ans = 0
break
return
t1, t2 = game[round]
for x, y in ((0, 2), (1, 1), (2, 0)):
if res[t1][x] > 0 and res[t2][y] > 0:
res[t1][x] -= 1
res[t2][y] -= 1
solution(round + 1)
res[t1][x] += 1
res[t2][y] += 1
answer = []
game = list(cb(range(6), 2))
# 백트래킹
for _ in range(4):
data = list(map(int, stdin.readline().split()))
res = [data[i:i + 3] for i in range(0, 16, 3)]
ans = 0
solution(0)
answer.append(ans)
print(*answer)
DFS 로 하려고 하니까 시간초과 + 메모리 초과 오류가 발생했다.
백트래킹으로 다시 풀어봐야할 것 같다.
DFS 방식에서 백트래킹 방식으로 변경
DFS와 백트래킹의 차이를 잡기가 조금 어려운 것 같다.
조금 더 개념에 익숙해진 후에 소스 적용을 더 해봐야할 것 같다.