Descriptionn students stood in a row, and the music teacher asked the (N-K) students to make the remaining K students lined up.
A queue is a formation in which K students are numbered 1, 2,… from left to right ,..., K. Their heights are T1, T2 ,..., TK, then their height is equal to t1 <t2 <... <Ti, Ti> Ti + 1>... > TK (1 <= I <= K ).
Your task is to know the height of all N students. The calculation requires at least a few students to make the remaining students form a queue.
The first line of input is an integer N (2 <= n <= 100), indicating the total number of students. The first line contains N integers separated by spaces. the I-th integer Ti (130 <= Ti <= 230) is the height (cm) of the I-th student ).
Output includes a row. This row contains only one integer, that is, at least a few columns are required.
Sample input8
186 186 150 200 160 130 197
Sample output4
Solution:Select a student in the queue and take the student as the core. Find the longest ascending subsequence on the left and the longest descending subsequence on the right, respectively, the sum of the two minus 1 is the number of the student-centered teams. Therefore, we only need to traverse each student as the center to obtain the largest number of student teams, the total number minus the chorus number is the number of people to be removed.
AC code:
# Include <iostream> # include <cstdio> # define max_num 105 using namespace STD; int main () {int high [max_num], left [max_num], right [max_num], n; scanf ("% d", & N); For (INT I = 0; I <n; I ++) scanf ("% d ", & high [I]); For (INT I = 0; I <n; I ++) {left [I] = 1; for (Int J = 0; j <I; j ++) {If (high [J]