We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f0c7dde commit 5333b90Copy full SHA for 5333b90
Dynamic_Programming/2140.Solving-Questions-With-Brainpower/Readme.md
@@ -0,0 +1,19 @@
1
+### 2140.Solving-Questions-With-Brainpower
2
+
3
4
+#### 解法3 (错误)
5
+令dp[i]表示处理前i个元素能取得的最大值。
6
+```cpp
7
+for (int i=0; i<n; i++)
8
+ dp[i] = questions[i][0];
9
10
+{
11
+ int skip = questions[i][1];
12
+ if (i+1<n)
13
+ dp[i+1] = max(dp[i+1], dp[i]);
14
+ if (i+skip+1<n)
15
+ dp[i+skip+1] = max(dp[i+skip+1], dp[i] + questions[i+skip+1][0]);
16
+ ret = max(ret, dp[i]);
17
+}
18
+```
19
+其中的问题在于,有这么一种情况:dp[i]对应着本身没有取第i个元素,因此它的值来源于dp[i-1];同时dp[i-1]对应着取了第i-1个元素。取第i-1个元素可能意味着一个从i-1开始需要有一个很大的skip,但是我们却是根据第i个元素的skip来更新dp[i+skip+1],这是不合理的。
0 commit comments