Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[백준] 2251 물통 [Python, 파이썬] 본문
- 문제 : https://www.acmicpc.net/problem/2251
- 🔑 물통의 이동 경우의 수 6가지
- C → A
- C → B
- B → A
- B → C
- A → B
- A → C
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))
'백준' 카테고리의 다른 글
[백준] 1753 최단경로 [Python, 파이썬] (2) | 2023.10.20 |
---|---|
[백준] 6443 애너그램 [Python, 파이썬] (0) | 2023.10.20 |
[백준] 26170 사과 빨리 먹기 [Python, 파이썬] (0) | 2023.10.19 |
[백준] 22944 죽음의 비 [Python, 파이썬] (1) | 2023.10.16 |
[백준] 2667 단지 번호 붙이기 [Python, 파이썬] (0) | 2023.10.15 |
Comments