public int maxDotProduct(int[] nums1, int[] nums2) {
int m = nums1.length;
int n = nums2.length;
int[][] dp = new int[2][n];
dp[0][0] = nums1[0] * nums2[0];
for (int j = 1; j < n; j++) {
dp[0][j] = Math.max(dp[0][j - 1], nums1[0] * nums2[j]);
}
int base = 1;
for (int i = 1; i < m; i++) {
dp[base][0] = Math.max(dp[base ^ 1][0], nums1[i] * nums2[0]);
for (int j = 1; j < n; j++) {
dp[base][j] = Math.max(Math.max(dp[base ^ 1][j], Math.max(dp[base ^ 1][j - 1], 0) + nums1[i] * nums2[j]), dp[base][j - 1]);
}
base ^= 1;
}
return dp[base^1][n-1];
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.