2
* @param {number[]} nums3
* @param {number[]} multipliers6
var maximumScore = function (nums, multipliers) {7
// using an array as memo will be faster8
// in processing than using an object9
let memo = new Array(multipliers.length + 1)11
.map(() => new Array(multipliers.length + 1).fill(0));13
// starting point will be from the end14
for (let i = multipliers.length - 1; i >= 0; i--) {15
// at state i, used i elements from nums16
// and left nums.length - i consecutive elements17
// those consecutive elements can be seen as the rest block18
// the left of the rest block can be any where from i to 019
// whereas the left element that this state can use is from the rest block21
for (let left = i; left >= 0; left--) {22
let right = nums.length - 1 - (i - left);24
// calculate all possible cases for state i25
// each case will combine with each case of state i - 1 and so on26
memo[i][left] = Math.max(27
multipliers[i] * nums[left] + memo[i + 1][left + 1],28
multipliers[i] * nums[right] + memo[i + 1][left]33
// finish the calculation and34
// return the last case that we calculated