alignment--poj1836

Source: Internet
Author: User

Description

In the army, a platoon was composed by N soldiers. During the morning inspection, the soldiers is aligned in a straight line in front of the captain. The captain is not a satisfied with the A-soldiers is aligned; It was true that the soldiers was aligned in order by their code number:1, 2, 3, ..., N, but they was not aligned B Y their height. The captain asks some soldiers to get out of the the line, as the soldiers that remain on the line, without changing their pla CES, but getting closer, to form a new line, where each soldier can see by looking lengthwise the line at least one of the Line ' s extremity (left or right). A soldier see a extremity if there is ' t any soldiers with a higher or equal height than he height between him and that Extremity.

Write a program this, knowing the height of each soldier, determines the minimum number of soldiers which has to get out of line.

Input

The first line of the input is written the number of the soldiers N. On the second line was written a series of n floating numbers with at most 5 digits precision and separated by a space char Acter. The k-th number from the "This" line represents the height of the soldier, who has the code K (1 <= k <= N).

There is some restrictions:
·2 <= N <= 1000
the height is floating numbers from the interval [0.5, 2.5]

Output

The only line of output would contain the number of the soldiers who has to get out of the the line.

Sample Input

81.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

4

Test instructions is an n-soldier queued, which eventually makes each soldier's left or right person's height drop at a time, asking for the minimum number of people out of the team, i.e. the total number minus the maximum remaining number;
The increment subsequence from left to right and increment subsequence from right to left can be obtained first.


The code is as follows:

#include <iostream>#include<stdio.h>#include<cstring>using namespacestd;#defineMAXN 1010DoubleS[MAXN];intA[MAXN],B[MAXN];intN;intMain () { while(cin>>N) {inti,j;  for(i=1; i<=n; i++) scanf ("%LF",&S[i]); a[1]=1;  for(i=2; i<=n; i++)//calculate the longest increment sequence from the beginning{A[i]=1;  for(j=1; j<i; J + +)            {                if(s[i]>s[j]&&a[j]>=A[i]) a[i]=a[j]+1; }} B[n]=1;  for(i=n-1; i>=1; i--)//calculates the longest increment sequence from the tail{B[i]=1;  for(J=n; j>i; j--)            {                if(s[i]>s[j]&&b[j]>=B[i]) b[i]=b[j]+1; }        }        intmaxn=-100000;//Initialize Max         for(i=1; i<=n; i++)        {             for(j=i+1; j<=n; J + +)            {                if(a[i]+b[j]>maxn) MAXN=a[i]+B[j]; }} printf ("%d\n", N-MAXN); }    return 0;}

alignment--poj1836

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.