I wish to solve a problem with a recursive function using two memoization dictionaries, but I'm not sure how to execute this idea.
From what I have learned, when using just one memoization dicionary, the code structure looks similar. For example, to solve Fibonacci number:
def fib_mem(n,mem=None):
if n < 2:
return n
if mem == None:
mem = {}
if n not in mem:
mem[n] = fib_mem(n-1,mem) + fib_mem(n-2,mem)
return mem[n]
What should I add to the code to use two memoization dicitionaries? What should I add to the def
line, and in the recursive calls?
my problem:
list = [(16, 1, 4), (17, 2, 9), (3, 17, 10)]
which list [i][0]
is the values. I should get the maximum possible combination values, considering two limiting factors given: list[i][1]
and list[i][2]
.
I can't fathom why you would want to use two different dictionaries, but I'd use a decorator