AcWing 482. 合唱队形
原题链接
简单
作者:
YMYS
,
2024-12-19 08:28:01
,
所有人可见
,
阅读 7
/*
* @Author: YMYS
* @Date: 2024-12-17 08:44:40
* @LastEditTime: 2024-12-19 08:23:47
* @FilePath: \VScode-C&C++-Coding\Acwing\算法提高课\1.动态规划\2.最长上升子序列模型\3.合唱队形.cpp
* @URL:https://www.acwing.com/problem/content/description/484/
* @Description: 482. 合唱队形
* 思路:出列的人最少,就是留下的人最多
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int n;
int w[N], f[N], g[N];
int main()
{
#ifdef ABC
freopen("D:\\daily_Coding\\VScode-C&C++-Coding\\in.in", "r", stdin);
freopen("D:\\daily_Coding\\VScode-C&C++-Coding\\out.out", "w", stdout);
#endif
cin>>n;
for(int i=1;i<=n;i++) cin>>w[i];
//正向LIS
for(int i=1;i<=n;i++){
f[i] = 1;
for(int j=1;j<i;j++){
if(w[i] > w[j]){
f[i] = max(f[i], f[j]+1);
}
}
}
//反向LIS
for(int i=n;i>=1;i--){
g[i] = 1;
for(int j=n;j>i;j--){
if(w[i] > w[j]){
g[i] = max(g[i], g[j]+1);
}
}
}
int res = 1;
for(int i =1;i<=n;i++){
res = max(res, f[i] + g[i] - 1);
}
cout<<n-res<<endl;
return 0;
}