OSDN Git Service

修正最长不下降子序列nlogn解法的代码错误
authorLincolnYe <48617718+LincolnYe@users.noreply.github.com>
Tue, 22 Sep 2020 04:18:04 +0000 (12:18 +0800)
committerGitHub <noreply@github.com>
Tue, 22 Sep 2020 04:18:04 +0000 (12:18 +0800)
如该解法中代码上面的算法描述,在dp中找到第一个大于a[i]的元素,则应该使用upper_bound,而不是lower_bound。

docs/dp/basic.md

index 0a4bf77..f4371d8 100644 (file)
@@ -160,7 +160,7 @@ for (int i = 0; i < n; ++i) scanf("%d", a + i);
 memset(dp, 0x1f, sizeof dp);
 mx = dp[0];
 for (int i = 0; i < n; ++i) {
-  *std::lower_bound(dp, dp + n, a[i]) = a[i];
+  *std::upper_bound(dp, dp + n, a[i]) = a[i];
 }
 ans = 0;
 while (dp[ans] != mx) ++ans;