zbojin @ 2023-08-12 20:38:57
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, dp[100005], mx, ans;
int *g;
struct Number {
int p1, p2;
} a[100005];
bool cmp(Number a, Number b) {
return a.p1 < b.p1;
}
int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", &a[i].p1);
for(int i = 0; i < n; ++i)
scanf("%d", &a[i].p2);
sort(a, a + n, cmp);
memset(dp, 0x3f, sizeof(dp));
for(int i = 0; i < n; ++i) {
g = upper_bound(dp, dp + ans, a[i].p2);
*g = a[i].p2;
if(g - dp == ans) ++ans;
}
printf("%d", ans);
return 0;
}
我把LCS转换成求最长上升子序列问题,用了upper_bound 这个 STL 函数,样例输出正确,实现最长上升子序列问题也过了模板题(B3637)。一定要手写吗?
by Aesyl @ 2023-08-15 11:42:25
@zbojin lower_bound吧,upper_bound用于最长不降子序列的求解
by zbojin @ 2023-08-15 13:50:21
OK,知道了
by zbojin @ 2023-08-15 13:55:08
改成 lower_bound 后还是 30 分
by thomasx1206 @ 2023-08-15 15:43:52
看这里,排序法会假
讨论区传送门
by zbojin @ 2023-08-19 16:50:47
已 AC , 此篇结