大佬们帮我看看为什么全都runtime error,py的代码
  • 板块P1464 Function
  • 楼主F1ower
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/25 09:48
  • 上次更新2024/10/25 12:33:35
查看原帖
大佬们帮我看看为什么全都runtime error,py的代码
1423113
F1ower楼主2024/10/25 09:48
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
2024/10/25 09:48
加载中...