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