Skip to content

Commit b98b088

Browse files
committed
1799
1 parent acf43e4 commit b98b088

File tree

1 file changed

+11
-1
lines changed
  • leetcode/1799. Maximize Score After N Operations

1 file changed

+11
-1
lines changed

leetcode/1799. Maximize Score After N Operations/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,20 @@ dp[m] = max( cnt / 2 * gcd(A[i], A[j]) + dp[next] )
6464

6565
where `i `and `j` are two different indexes of bit 1s in `m`, and `next = m & ~(1 << i) & ~(1 << j)` represents the subset `m` excluding `A[i]` and `A[j]`.
6666

67+
### Complexity Analysis
68+
69+
We traverse the binary masks from `2` to `2^N - 1` so the outer `for` loop will run `O(2^N)` time.
70+
71+
In each round of `for` loop, we take `O(N^2)` time to traverse all the pairs of elements in the subset `m`.
72+
73+
Thus, overall it takes `O(2^N * N^2)` time.
74+
75+
And the space complexity is apparently `O(2^N)` as well because of the `dp` array.
76+
6777
```cpp
6878
// OJ: https://leetcode.com/problems/maximize-score-after-n-operations/
6979
// Author: github.com/lzl124631x
70-
// Time: O(2^N)
80+
// Time: O(2^N * N^2)
7181
// Space: O(2^N)
7282
class Solution {
7383
public:

0 commit comments

Comments
 (0)