这家伙很勤快,奖个金钩吧
还需学习算法:
1、 套
2、动态
3、基环树
4、后缀自动机
5、后缀数组
6、马拉车
7、 函数
8、模拟退火
9、爬山算法
10、折半搜索
11、 搜索
12、重构树
13、prefer序列
未写完代码保存:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int dp[N],n;
vector<int> g[N];
inline bool cmp(node a,node b){
if(a.v!=b.v) return a.v<b.v;
else return a.id<b.id;
}
signed main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].v,a[i].id=i;
sort(a+1,a+1+n,cmp);
dp[1]=1;
for(int i=2;i<=n;i++){
//cout<<a[i].id<<'\n';
if(a[i].id>a[i-1].id) dp[i]=dp[i-1]+1;
else dp[i]=1;
}
int maxn=0;
for(int i=1;i<=n;i++) maxn=max(maxn,dp[i]);
cout<<n-maxn;
return 0;
}