나의 개발일지

[백준] 2251 물통 [Python, 파이썬] 본문

백준

[백준] 2251 물통 [Python, 파이썬]

YoonJuHan 2023. 10. 19. 20:29

 

one, two, three = map(int, input().split())
answer = []
m = max(one, two, three)
chk = [[[0] * (m+1) for _ in range(m+1)] for _ in range(m+1)]

def dfs(a, b, c):

    if chk[a][b][c] == 1:
        return
    if a == 0:
        answer.append(c)

    chk[a][b][c] = 1

    if c > (one - a):   # C -> A
        dfs(one, b, c - (one - a))
    else:
        dfs(a + c, b, 0)

    if c > (two - b):   # C -> B
        dfs(a, two, c - (two - b))
    else:
        dfs(a, b + c, 0)

    if b > (one - a):   # B -> A
        dfs(one, b - (one - a), c)
    else:
        dfs(a + b, 0, c)

    if b > (three - c):   # B -> C
        dfs(a, b - (three - c), three)
    else:
        dfs(a, 0, c + b)

    if a > (two - b):   # A -> B
        dfs(a - (two - b), two, c)
    else:
        dfs(0, b + a, c)

    if a > (three - c):   # A -> C
        dfs(a - (three - c), b, three)
    else:
        dfs(0, b, c + a)

dfs(0, 0, three)

print(*sorted(answer))
Comments