며칠째 규칙을 못 찾겠어서 검색을 해버렸다.. 그런데 매우 간단하더라. 동적이니까 그냥 저장을 미리 해버리는 방식이다. 최대한 재귀호출을 줄이는 것이다.
import sys
input = sys.stdin.readline
lst = [[[0]*21 for _ in range(21)] for _ in range(21)]
def w(a, b, c):
if a<=0 or b<=0 or c<=0:
return 1
if a>20 or b>20 or c>20:
return w(20, 20, 20)
if lst[a][b][c]:
return lst[a][b][c]
if a<b and b<c:
lst[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
return lst[a][b][c]
lst[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
return lst[a][b][c]
while True:
a, b, c = map(int, input().split())
if a==-1 and b==-1 and c==-1:
break
# print('w(', a, ', ', b, ', ', c, ') = ', w(a, b, c), sep='')
print(f'w({a}, {b}, {c}) = {w(a, b, c)}')
