Problem
The number of X (x>=0) is taken from the given number of N. Make the remaining number the most of the following properties.
A1 < A2 < A3 <, .... At > at+1 >at+2 > ... > As
Ask at least a few numbers to be drained. This series will only have the above properties.
Graphic
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvenh5odyxmte0/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "style=" WIDTH:589PX; height:431px ">
Code
#include "stdafx.h" const int max=105;int down[max],up[max];int h[max],n;void get_up () {int i,tmp,j;for (i=0;i<n;i++) {tmp=1;for (j=i-1;j>=0;j--) {if (h[i]>h[j]&&up[j]+1>tmp) tmp=up[j]+1;} Up[i]=tmp;}} void Get_down () {int i,j,tmp;for (i=n-1;i>=0;i--) {tmp=1;for (j=i+1;j<n;j++) {if (h[i]>h[j]&&down[j]+ 1>tmp) tmp=down[j]+1;} Down[i]=tmp;}} int main () {int i,max;while (scanf ("%d", &n)!=eof) {for (i=0;i<n;i++) scanf ("%d", &h[i]); get_up (); Get_down () ; Max=0;for (i=0;i<n;i++) {if (Up[i]+down[i]-1>max) max=up[i]+down[i]-1;} printf ("%d\n", N-max);} return 0;}
Algorithm: Longest ascending descent sub-sequence