Timeline (one-dimensional linear dp recurrence)

Source: Internet
Author: User

Timeline (one-dimensional linear dp recurrence)
DescriptionDescriptionN 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, and so on from left to right ..., K. Their heights are T1, T2 ,..., TK, then their height meets T1 <... 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 of the input file chorus. in 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 file chorus. out contains a row. This row contains only one integer, that is, at least a few students are required to columns.
8
186 186 150 200 160 130 197

4

#include
 
  #include
  
   #include
   
    #include
    
     using namespace std;int que[110];int dp_u[110];int dp_d[110];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i
     
      mu&&que[i]>que[j])                    mu=dp_u[j];            }            dp_u[i]=mu+1;        }        for(int i=n-2;i>=0;i--){            int md=0;            for(int j=n-1;j>i;j--){                if(dp_d[j]>md&&que[i]>que[j])                    md=dp_d[j];            }            dp_d[i]=md+1;        }        int res=10000;        for(int i=0;i
      
       

Related Article

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.