标签:UNC not foo wrap 分治 mem ret 动态规划 *args
def memo(func):
cache = {}
def wrap(*args):
if args not in cache:
cache[args] = func(*args)
return cache[args]
return wrap
@memo # 注释掉这个装饰器
def fib(i):
if i < 2:
return 1
return fib(i-1) + fib(i-2)
print(fib(55))
cache = {}
def memo(func):
def wrap(*args):
if args not in cache:
cache[args] = func(*args)
return cache[args]
return wrap
@memo
def fib(i):
if i < 2:
return 1
return fib(i-1) + fib(i-2)
print(fib(55))
print(cache)
def foo(*args):
print(args)
args = (1,2,34,)
foo(*args)
foo(args)
标签:UNC not foo wrap 分治 mem ret 动态规划 *args
原文地址:https://www.cnblogs.com/allen2333/p/9473460.html