There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:
You will pick any pizza slice.
Your friend Alice will pick the next slice in the anti-clockwise direction of your pick.
Your friend Bob will pick the next slice in the clockwise direction of your pick.
Repeat until there are no more slices of pizzas.
Given an integer array slices that represent the sizes of the pizza slices in a clockwise direction, return the maximum possible sum of slice sizes that you can pick.
classSolution { inthelper(vector<int> A, int m){ int res = 0, n = A.size(); vector<vector<int>> dp(n + 2, vector<int>(m + 1)); for(int i = 2; i < n + 2; i++) { for(int j = 1; j <= m; j++) { // use max for eat(i - 1)th pizza as jth eat (i - 2)th pizza as jth with max for skip 2 pizza with (j - 1)th dp[i][j] = max(dp[i-1][j], dp[i-2][j-1] + A[i-2]); res = max(res, dp[i][j]); } }
return res; } public: intmaxSizeSlices(vector<int>& slices){ int n = slices.size(); returnmax( helper(vector<int>(slices.begin(), slices.begin() + n - 1), n / 3), helper(vector<int>(slices.begin() + 1, slices.begin() + n), n / 3) ); } };