You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2100-2199/2140.Solving Questions With Brainpower/README_EN.md
+52-8
Original file line number
Diff line number
Diff line change
@@ -77,18 +77,18 @@ Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.
77
77
78
78
<!-- solution:start -->
79
79
80
-
### Solution 1: Memoization Search
80
+
### Solution 1: Memoization
81
81
82
-
We design a function $dfs(i)$, which represents the maximum score that can be obtained starting from the $i$-th problem. Therefore, the answer is $dfs(0)$.
82
+
We design a function $\textit{dfs}(i)$, which represents the maximum score that can be obtained starting from the $i$-th question. The answer is $\textit{dfs}(0)$.
83
83
84
-
The calculation method of the function $dfs(i)$ is as follows:
84
+
The function $\textit{dfs}(i)$ is calculated as follows:
85
85
86
-
- If $i \geq n$, it means that all problems have been solved, return $0$;
87
-
- Otherwise, let the score of the $i$-th problem be $p$, and the number of problems to skip be $b$, then $dfs(i) = \max(p + dfs(i + b + 1), dfs(i + 1))$.
86
+
- If $i \geq n$, it means all questions have been solved, so return $0$;
87
+
- Otherwise, let the score of the $i$-th question be $p$, and the number of questions to skip be $b$. Then, $\textit{dfs}(i) = \max(p + \textit{dfs}(i + b + 1), \textit{dfs}(i + 1))$.
88
88
89
-
To avoid repeated calculations, we can use the method of memoization search, using an array $f$ to record the values of all already computed $dfs(i)$.
89
+
To avoid repeated calculations, we can use memoization by storing the values of $\textit{dfs}(i)$ in an array $f$.
90
90
91
-
The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the number of problems.
91
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the number of questions.
92
92
93
93
<!-- tabs:start -->
94
94
@@ -144,7 +144,7 @@ public:
144
144
int n = questions.size();
145
145
long long f[n];
146
146
memset(f, 0, sizeof(f));
147
-
function<long long(int)> dfs = [&](int i) -> long long {
147
+
auto dfs = [&](this auto&& dfs, int i) -> long long {
148
148
if (i >= n) {
149
149
return 0;
150
150
}
@@ -201,6 +201,32 @@ function mostPoints(questions: number[][]): number {
0 commit comments