20pts 求助
查看原帖
20pts 求助
685602
Chtholly_Tree楼主2023/3/12 20:51

Code:

#include <bits/stdc++.h>
using namespace std;
int n,a[1000010],f[1000010],d[1000010];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>a[i];
	for (int i=1; i<=n; i++) {
		f[i]=1;
		for (int j=1; j<i; j++) {
			if (a[j]<a[i]) f[i]=max(f[i],f[j]+1);
		}
	}
	for (int i=1; i<=n; i++) {
		d[i]=max(f[i-1]+1,f[i+1]-1);
	}
	cout<<d[n]<<"\n";
	return 0;
}
2023/3/12 20:51
加载中...