Maximum Score from Performing Multiplication Operations LeetCode solution in C++

1
class Solution {
2
public:
3
int maximumScore(vector<int> &nums, vector<int> &multipliers) {
4
const int m = multipliers.size();
5
const int n = nums.size();
6
vector<vector<int>> dp(m + 1, vector<int>(m + 1));
7
for (auto z = 0; z < m; ++z) {
8
int row{0};
9
int col{z + 1};
10
while (col >= 0) {
11
dp[row][col] = max((row > 0 ? dp[row - 1][col] + nums[row - 1] * multipliers[z] : INT_MIN),
12
(col > 0 ? dp[row][col - 1] + nums[n - col] * multipliers[z] : INT_MIN));
13

14
--col;
15
++row;
16
}
17
}
18

19
auto maxScore = INT_MIN;
20
for (auto row = 0; row <= m; ++row) {
21
maxScore = max(maxScore, dp[row][m - row]);
22
}
23

24
return maxScore;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0