leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit a3aa09bd62446af77349b1c7c9bfe3c403267535
parent e08bc1709519917d51e1cec76b971f66fa164d4e
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Sun, 14 May 2023 18:45:20 +0200

Daily Problem

Diffstat:
A Problems/1799.cpp | +++++++++++++++++++++
M README.md | ++++ ---

2 files changed, 25 insertions(+), 3 deletions(-)


diff --git a/ Problems/1799.cpp b/ Problems/1799.cpp

@@ -0,0 +1,21 @@
class Solution {
int dp[8][16384];
public:
Solution() { memset(dp, 0xFF, sizeof(dp)); }
int maxScore(vector<int> &n, int i = 1, int mask = 0) {
if (i > n.size() / 2) return 0;
if (dp[i][mask] != -1) return dp[i][mask];
dp[i][mask] = 0;
for (int j = 0; j < n.size(); j++) {
for (auto k = j + 1; k < n.size(); k++) {
int new_mask = (1 << j) | (1 << k);
if ((mask & new_mask)) continue;
dp[i][mask] = max(dp[i][mask], i * gcd(n[j], n[k]) +
maxScore(n, i + 1, mask + new_mask));
}
}
return dp[i][mask];
}
};

diff --git a/ README.md b/ README.md

@@ -480,6 +480,7 @@ for solving problems. | 1768 | Easy | [Merge Strings Alternately](Problems/1768.cpp) | | 1786 | Medium | [Number of Restricted Paths From First to Last Node](Problems/1786.cpp) | | 1791 | Easy | [Find Center of Star Graph](Problems/1791.cpp) |
| 1799 | Medium | [Maximize Score After N Operations](Problems/1799.cpp) |
| 1822 | Easy | [Sign of the Product of an Array](Problems/1822.cpp) | | 1823 | Medium | [Find the Winner of the Circular Game](Problems/1823.cpp) | | 1833 | Medium | [Maximum Ice Cream Bars](Problems/1833.cpp) |

@@ -539,11 +540,11 @@ for solving problems. | 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) | | 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) | | 2620 | Easy | [Counter](Problems/2620.js) |
| 2623 | Medium | [Memoize](Problems/2623.js) |
| 2626 | Easy | [Array Reduce Transformation](Problems/2626.js) | | 2629 | Easy | [Function Composition](Problems/2629.js) | | 2634 | Easy | [Filter Elements from Array](Problems/2634.js) | | 2635 | Easy | [Apply Transform Over Each Element in Array](Problems/2635.js) | | 2665 | Easy | [Counter II](Problems/2665.js) |
| 2666 | Easy | [Allow One Function Call](Problems/2666.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |
| 2623 | Medium | [Memoize](Problems/2623.js) |
| 2666 | Easy | [Allow One Function Call](Problems/2666.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |