近期错误
- TLE,RE时调试要输出endl,否则可能输出偏少导致判断寄的位置偏前。
- 写到了最里层循环内。
- 转移,移动顺序不对。导致被覆盖或重复转移。
一种错误的LIS写法
最小的不一定是最长的。
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int n, a[N], b[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int top=0,ans=0;
for(int i=1;i<=n;i++){
while(top&&a[b[top]]>a[i]){
top--;
}
b[++top]=i;
ans=max(ans,top);
}
printf("%d",ans);
return 0;
}
/*
hack:
5
1 3 4 2 5
*/