Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: Java  |  size: 1.17 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package coding;
  6.  
  7. import com.sun.corba.se.impl.encoding.BufferManagerFactory;
  8. import java.io.BufferedReader;
  9. import java.io.InputStreamReader;
  10.  
  11. /**
  12.  *
  13.  * @author Mohamed
  14.  */
  15. public class Coding {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
  22.        
  23.        int a[]={1 ,4 ,2 ,4 ,3};
  24.         System.out.println( LIS(a));
  25.     }
  26.  
  27.     public static int LIS(int[] a) {
  28.         int n = a.length;
  29.         int max;
  30.         int[] q = new int[n];
  31.         for (int k = 0; k < n; k++) {
  32.             max = 0;
  33.             for (int j = 0; j < k; j++) {
  34.                 if (a[k] > a[j]) {
  35.                     if (q[j] > max) {
  36.                         max = q[j];
  37.                     }
  38.                 }
  39.             }
  40.              q[k] = max + 1;
  41.         }
  42.         max = 0;
  43.         for (int i = 0; i < n; i++) {
  44.             if (q[i] > max) {
  45.                 max = q[i];
  46.             }
  47.         }
  48.         return max;
  49.     }
  50. }