已AC,但不明白原来的做法为什么WA80pts
查看原帖
已AC,但不明白原来的做法为什么WA80pts
511811
崛起的滑稽楼主2024/8/15 12:40

思路:枚举中间那个人,在两边进行最长上升/下降子序列求解
WA#2#9

#include <bits/stdc++.h>
//#define int int64_t
//#define int __int128
//#define MOD (1000000007)
//#define eps (1e-6)
#define endl '\n'
#define debug cout<<"debug"<<endl;
using namespace std;
const int MAXN=110;
int n;
int a[MAXN],ans;
vector<int> lst1,lst2;
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	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){
		lst1.clear();
		lst2.clear();
		for(int j=1;j<=i;++j){
			if(j==1||a[j]>lst1.back()){
				lst1.push_back(a[j]);
			}
			else{
				int index=upper_bound(lst1.begin(),lst1.end(),a[j])-lst1.begin();
				lst1[index]=a[j];
			}
		}
		for(int j=i;j<=n;++j){
			if(j==i||a[j]<lst2.back()){
				lst2.push_back(a[j]);
			}
			else{
				int index=upper_bound(lst2.begin(),lst2.end(),a[j],greater<int>())-lst2.begin();
				lst2[index]=a[j];
			}
		}
		ans=max(ans,int(lst1.size())+int(lst2.size())-1);
	}
	cout<<n-ans;
	return 0;
}
2024/8/15 12:40
加载中...