Advertisement
kic10

Za drash

Nov 19th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class LDS {
  5.  
  6.  
  7. private static int najdolgaOpagackaSekvenca(int[] a) {
  8. int [] best = new int[a.length];
  9.  
  10. for (int i=0; i<a.length;++i)
  11. best[i] = 1;
  12.  
  13. for (int i = 1; i < a.length; i++){
  14. for (int j = 0; j < i; j++){
  15. if (a[j] > a[i]&&best[i] < best[j] + 1)
  16. best[i] = best[j] + 1;
  17. }
  18. }
  19.  
  20. int min = 0;
  21. for (int i = 0; i < best.length; i++)
  22. if (best[i] > min)
  23. min = best[i];
  24.  
  25. return min;
  26. }
  27.  
  28. public static void main(String[] args) {
  29. Scanner stdin = new Scanner(System.in);
  30.  
  31. int n = stdin.nextInt();
  32. int a[] = new int[n];
  33. for (int i = 0; i < a.length; i++) {
  34. a[i] = stdin.nextInt();
  35. }
  36. System.out.println(najdolgaOpagackaSekvenca(a));
  37. }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement