• Source
    1. import java.util.*;
    2.  
    3. class Ideone{
    4.  
    5. public static void main(String[] args){
    6. int[] a = { 10, 22, 9, 33, 21, 50, 41, 60, 80 }; //max increasing subsequence length of this sequence is 6
    7.  
    8. int[] longIncSeq = new int[a.length];
    9.  
    10. //Every element is part of its longest increasing subsequence
    11. for(int i=0; i<a.length; i++)
    12. longIncSeq[i] = 1;
    13.  
    14. //Now check longest increasing sequence for every sequence end with ith position of args
    15. for(int i=0; i<a.length; i++){
    16. for(int j=0; j<i; j++){
    17. if(a[i] > a[j] && longIncSeq[i] < longIncSeq[j]+ 1){
    18. longIncSeq[i] = longIncSeq[j]+1;
    19. }
    20. }
    21. }
    22.  
    23. //Find the max value and print it
    24. int maxSeqLength = 0 ;
    25. for(int i=0; i < longIncSeq.length; i++){
    26. maxSeqLength = maxSeqLength > longIncSeq[i] ? maxSeqLength : longIncSeq[i];
    27. }
    28.  
    29. System.out.println("Longest increasing subsequene length => "+ maxSeqLength);
    30. }
    31. }
    32.