1seul357

[SWEA] 격자판의 숫자 이어붙이기 본문

알고리즘/SWEA

[SWEA] 격자판의 숫자 이어붙이기

1seul 2021. 11. 28. 16:15
def dfs(row, col, cnt, ans):
    dr = [-1, 1, 0, 0]
    dc = [0, 0, -1, 1]
    if cnt == 7:
        answer.append(ans)
        return
    for i in range(4):
        now_dr = row + dr[i]
        now_dc = col + dc[i]
        if 0 <= now_dr < 4 and 0 <= now_dc < 4:
            tmp = ans
            ans += arr[now_dr][now_dc]
            dfs(now_dr, now_dc, cnt+1, ans)
            ans = tmp

T = int(input())
for TC in range(T):
    arr = [list(map(str, input().split())) for _ in range(4)]
    answer = []

    for i in range(4):
        for j in range(4):
            dfs(i, j, 0, '0')
    result = set(answer)
    a = len(result)

    print('#{} {}'.format(TC+1, a))

'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA] 보급로  (0) 2021.11.28
[SWEA] N Castle  (0) 2021.11.28
[SWEA] 장훈이의 높은 선반  (0) 2021.11.28
[SWEA] 정사각형 방  (0) 2021.11.28
[SWEA] 그룹 나누기  (0) 2021.11.28