12.19
DP
- P1091: find the highest chorus formation.
Thinking : dp1 [i] i is represented by the last one, 1-i in the LIS, dp2 [i] i is represented by a first individual, in the LDS. run front to back dp1, dp2 running from the back. Note, not front to back of the LDS.
#include<bits/stdc++.h>
using namespace std;
const int M=140;
int a[M],n,ans[M];
struct LIS{
int dp[M],d[M];
void run(){
int len=0;
for(int i=1;i<=n;++i){
int p=lower_bound(d+1,d+len+1,a[i])-d;//找到第一个大于等于a[i]的下标
dp[i]=p,d[p]=a[i];
if (p>len)
len=p;
}
}
}L1;
struct LDS{
int dp[M],d[M];
void run(){
int len=0;
for(int i=n;i>=1;--i){
int p=lower_bound(d+1,d+len+1,a[i])-d;//找到第一个大于等于a[i]的下标
dp[i]=p,d[p]=a[i];
if (p>len)
len=p;
}
}
}L2;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
L1.run(),L2.run();
int ans=0;
for(int i=1;i<=n;++i)
ans=max(ans,L1.dp[i]+L2.dp[i]-1);
printf("%d\n",n-ans);
return 0;
}