Maximum Score from Performing Multiplication Operations LeetCode solution in C++
1class Solution {2public:3int maximumScore(vector<int> &nums, vector<int> &multipliers) {4const int m = multipliers.size();5const int n = nums.size();6vector<vector<int>> dp(m + 1, vector<int>(m + 1));7for (auto z = 0; z < m; ++z) {8int row{0};9int col{z + 1};10while (col >= 0) {11dp[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));1314--col;15++row;16}17}1819auto maxScore = INT_MIN;20for (auto row = 0; row <= m; ++row) {21maxScore = max(maxScore, dp[row][m - row]);22}2324return maxScore;25}26};