"TYVJ" P1049 the longest non-descending sub-sequence

Source: Internet
Author: User

Time: 1000ms/Space: 131072kib/java class Name: Main

Describe

To find the longest non-descending subsequence length

Input format

The first action n, which means n number of the second row n

Output format

Length of the longest non-descending sub-sequence

Test Sample 1

Input

3

1 2 3

Output

3

Note

N Less than 5000

For each num <=maxint

Let's get an array. f[i] represents the longest length of the number of previous I, and at first all 1 is himself. Then cycle through the 0~n-1 first. I =0 ~ n-1 for each a[i] the number behind him is set to A[j] (j>i)

If a[j]>a[i] That means it is possible to be counted as the eldest son of the sequence.

At this time for A[i] is nothing but two cases, one is followed by J mixed, one is not with. So F[j]=max (F[i]+1,f[j])

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 intMain ()8 {9     intn,max=0;TenCin>>N; One     intf[ the],a[ the]; A      for(intI=0; i<n; ++i) -Cin>>A[i]; -  the      for(intI=0; i<n;++i) -f[i]=1; -      for(intI=0; i<n-1; ++i) { -          for(intj=i+1; j<n;++j) +             if(a[j]>=a[i]&&f[i]+1>F[j]) -f[j]=f[i]+1; +     } A      for(intI=0; i<n; ++i) at         if(max<F[i]) -max=F[i]; -  -cout<<max<<Endl; -     return 0; -}

"TYVJ" P1049 the longest non-descending sub-sequence

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.