Untitled
Anonymous
plain_text
12/02/2023 5:45 PM
604 B
17
Indexable
from functools import lru_cache
class Solution:
def maxDotProduct(self, a: List[int], b: List[int]) -> int:
@lru_cache(None)
def dp(i, j):
if i < 0 or j < 0:
return -math.inf
return max(
a[i] * b[j],
a[i] * b[j] + dp(i - 1, j - 1),
dp(i, j - 1),
dp(i - 1, j)
)
return dp(len(a) - 1, len(b) - 1)Editor is loading...
Leave a Comment