-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path合唱队.cpp
36 lines (30 loc) · 789 Bytes
/
合唱队.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;
int main()
{
int n, stature[100], result = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> stature[i];
stature[n] = '\0';
int *listrise = new int[n]; //上升子序列
for (int i = 0; i < n; i++)
{
listrise[i] = 1;
for (int j = 0; j < i; j++)
if ((stature[i] > stature[j]) && (listrise[j] + 1 > listrise[i]))
listrise[i] = listrise[j] + 1;
}
int *listdown = new int[n];
for (int i = n - 1; i >= 0; i--)
{
listdown[i] = 1;
for (int j = n - 1; j > i; j--)
if ((stature[i] > stature[j]) && (listdown[j] + 1> listdown[i]))
listdown[i] = listdown[j] + 1;
}
for (int i = 0; i < n; i++)
if (listrise[i] + listdown[i] - 1> result)
result = listrise[i] + listdown[i] - 1;
cout << n - result << endl;
}