AveMujica @ 2024-10-25 09:48:21
memo = {}
def w(a, b, c):
if (a, b, c) in memo: return memo[(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 a < b and b < c: res = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c)
res = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1)
memo[(a, b, c)] = res
return res
result = []
while(True):
a, b, c = map(int, input().split())
if (a == -1) and (b == -1) and (c == -1): break
result.append(f"w({a}, {b}, {c}) = {w(a, b, c)}\n")
print(''.join(result))
控制台输出:
15 15 15
-1 -1 -1
w(15, 15, 15) = 32768
1 1 1
2 2 2
-1 -1 -1
w(1, 1, 1) = 2
w(2, 2, 2) = 4
by AveMujica @ 2024-10-25 09:52:32
已AC,a > 20 写成 a>= 20了