Description A Numeric sequence ofAIis ordered ifA1<A2< ... < an. Let the subsequence of the given numeric sequence (A1,A2, ..., an) is any sequence (Ai1,AI2, ...,AiK), where 1 <=I1<I2< ... <IK<=N. For example, sequence (1, 7, 3, 5, 9, 4, 8) have ordered Subsequences, E. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences is of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered.Input The first line of input file contains the length of sequence N. The second line contains the elements of sequence-n integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000Output Output file must contain a single integer-the length of the longest ordered subsequence of the given sequence.Sample Input 71 7 3 5 9 4 8
Sample Output 4
Source Northeastern Europe 2002, Far-eastern subregion |
To find the length of the longest increment sequence
Solving the puzzle: writing in another article
-------- http://www.cnblogs.com/Noevon/p/5685975.html
#include <stdio.h>intb[1010], a[1010];intMain () {intI, J, N, Max; scanf ("%d", &N); for(i=1; i<=n;i++) scanf ("%d", &A[i]); a[0] =0; for(i=1; i<=n;i++) { for(max=0, j=i;j>=0; j--) if(a[i]>a[j]&&max<B[j]) Max=B[j]; B[i]= max+1; } for(max=0, i=0; i<=n;i++) if(Max <B[i]) Max=B[i]; printf ("%d\n", Max); return 0;}
POJ 2533 longest Ordered subsequence maximum increment sequence