#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int pos[1001],cnt[1001],l[1001],r[1001];
int max_depth=0;
void dfs(int root,int u,int depth){
if(pos[u]<=pos[root]){
if(l[root]==INF){
l[root]=u;
cnt[depth+1]++;
max_depth=max(max_depth,depth+1);
return ;
}else{
dfs(l[root],u,depth+1);
return ;
}
}else{
if(r[root]INF){
r[root]=u;
cnt[depth+1]++;
max_depth=max(max_depth,depth+1);
return ;
}else{
dfs(r[root],u,depth+1);
return ;
}
}
}
int main(){
int n;
cin>>n;
memset(l,0x3f,sizeof(l));
memset(r,0x3f,sizeof®);
if(n1){
cout<<“1”<<endl;
return 0;
}
for(int i=0;i<n;i++){
int x;
cin>>x;
if(!i){
pos[i]=x;
}else{
pos[i]=x;
dfs(0,i,0);
}
}
cout<<cnt[max_depth-1]+cnt[max_depth]<<endl;
return 0;
}
【无标题】
最新推荐文章于 2024-04-07 10:22:37 发布