[Description]
N 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.
[Input format]
The first line 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 format]
The output includes a row. This row contains only one integer, that is, at least a few students are required for the column.
[Example input]
8
186 186 150 200 160 130 197
[Sample output]
4
[Analysis]
Find the longest ascending subsequence of the I point in both directions.
#include <stdio.h>#define MAXN 110int f1[MAXN],f2[MAXN],a[MAXN];int n,ans;int main() { scanf("%d",&n); for (int i = 1;i <= n;++i) scanf("%d",&a[i]); for (int i = 1;i <= n;++i) { f1[i] = 1; for (int j = 1;j < i;++j) if ((a[j] < a[i]) && (f1[j] + 1 > f1[i])) f1[i] = f1[j] + 1; } for (int i = n;i > 0;--i) { f2[i] = 1; for (int j = i + 1;j <= n;++j) if ((a[i] > a[j]) && (f2[j] + 1 > f2[i])) f2[i] = f2[j] + 1; } for (int i = 1;i <= n;++i) if (f1[i] + f2[i] > ans) ans = f1[i] + f2[i]; printf("%d\n",n - (ans - 1)); return 0;}