52分求助!!!!
查看原帖
52分求助!!!!
1059096
lcxzg楼主2024/8/8 19:37
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, cnt = 0;
const int N = 5e5 + 10;
vector<long long> f(N, 1);
vector<long long> f1(N, 1);
bool st[N];
int a[N], ct;
//动态规划 在计算当前时,前面的答案已经确定
int main() {
	cin >> n;
	while (cin >> a[++ct]) {
	}
//	f[1] = 1;
//	f[i]以a[i]结尾的最长上升子序列长度
	for (int i = 2; i <= ct; i++) {
		for (int j = 1; j < i; j++) {
			if (a[j] >= a[i]) {
				f[i] = max(f[i], f[j] + 1);
			}
		}
	}
	long long maxi = 0;
	for (int i = 1; i <= ct; i++) {
		maxi = max(maxi, f[i]);
	}
	cout << maxi << endl;
	maxi = 0;
	for (int i = 2; i <= ct; i++) {
			for (int j = 1; j < i; j++) {
				if (a[j] < a[i]) {
					f1[i] = max(f1[i], f1[j] + 1);
				}
			}
	}
	for (int i = 1; i <= ct; i++) {
			maxi = max(maxi, f1[i]);
		}
	cout << maxi;
	return 0;
}
2024/8/8 19:37
加载中...