有没有大佬看看提交了几次有的时候八十几分有的时候九十几分
查看原帖
有没有大佬看看提交了几次有的时候八十几分有的时候九十几分
1267057
aa2211034566楼主2024/2/26 20:24
#include<bits/stdc++.h>
using namespace std;
int LIS(int a[], int n) {
	int len ;  // 当前最长上升子序列的长度
	int b[n+1];   // 存储长度为 i 的所有上升子序列中,末尾元素最小的那个元素
	for (int i = 1; i <= n; i++) {
		if (a[i] > b[len]) {
			b[++len] = a[i];
		} else {
			int j = lower_bound(b+1, b+len+1, a[i]) - b;
			b[j] = a[i];
		}
	}
	return len;
}
int main(){
	int a[100010];
	int i=1;
	int x;
	while(cin>>x){
		a[i++]=x;
	}
	reverse(a+1,a+i+1);
	cout<<LIS(a,i)<<endl;
	reverse(a+1,a+i+1);
	cout<<LIS(a,i);
}

就是先逆序求上升的就当成下降的,然后用那个什么定理

2024/2/26 20:24
加载中...