N - Longest Ordered Subsequence POJ - 2533
Topic links: https://vjudge.net/contest/68966#problem/N
topic:
If the longest ordered subsequence a1 <a2 <... <aN, then the sequence of numbers sorted ai. Sequences give the given number sequence (a1, a2, ..., aN ) is any sequence (ai1, ai2, ..., aiK ), where 1 <= i1 <i2 <... <iK <= N For example, the sequence (1,7,3,5,9,4,8) having an ordered sequence, for example. g. , (1,7), (3,4,8) and many others. All longest ordered subsequence of length 4, e. g. , (1,3,5,8).
When a given sequence of numbers, your program must find its longest length of an ordered sequence.
Input
The first line of the input file comprises a sequence length of N. The second row contains the elements of a sequence - N integers, ranges, each separated by a space from 0 to 10,000. 1 <= N <= 1000
yields
an output file must contain an integer - for the longest length of an ordered sequence of a given sequence.
Sample input
. 7
. 1. 8. 7. 3 4. 5. 9
Sample Output
4
Thinking: LIS problems, we must pay attention dp [i] the initial value of 1;
// // Created by hanyu on 2019/8/8. // #include <algorithm> #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <set> #include<math.h> #include<map> using namespace std; typedef long long ll; const int maxn=1000+7; #define MAX 0x3f3f3f3f int main() { int T; while(~scanf("%d",&T)) { int dp[maxn],a[maxn]; memset(dp,0, sizeof(dp)); for(int i=0;i<T;i++) { scanf("%d",&a[i]); } for(int i=0;i<T;i++) { dp[i]=1; for(int j=0;j<=i;j++) { if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+1); } } int maxx=-1; for(int i=0;i<T;i++) { maxx=max(maxx,dp[i]); } printf("%d\n",maxx); } return 0; }