Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
451 B
0
Indexable
Never
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)
Leave a Comment