Advertisement
unknown_0711

Untitled

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