'commit'
This commit is contained in:
30
TangDou/AcWing/LIS/482_3.cpp
Normal file
30
TangDou/AcWing/LIS/482_3.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1010;
|
||||
|
||||
int n;
|
||||
int a[N];
|
||||
int f[N][2];
|
||||
|
||||
int main() {
|
||||
// input
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
|
||||
// dp
|
||||
for (int i = 1; i <= n; i++) {
|
||||
f[i][0] = f[i][1] = 1;
|
||||
for (int j = 1; j < i; j++) {
|
||||
if (a[j] < a[i]) f[i][0] = max(f[i][0], f[j][0] + 1);
|
||||
if (a[j] > a[i]) f[i][1] = max(f[i][1], max(f[j][0], f[j][1]) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// find result from all final states
|
||||
int res = 0;
|
||||
for (int i = 1; i <= n; i++) res = max({res, f[i][0], f[i][1]});
|
||||
cout << n - res << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user