Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LDS {
- private static int najdolgaOpagackaSekvenca(int[] a) {
- int[] dp = new int[a.length];
- for(int i = 0; i < a.length; i++) {
- dp[i] = 1;
- }
- for(int i = 0; i < a.length; i++) {
- for(int j = 0; j < i; j++) {
- if(a[i] > a[j]) {
- dp[i] = Math.max(dp[i], dp[j] + 1);
- }
- }
- }
- int res = 0;
- for(int i = 0; i < a.length; i++) {
- res = Math.max(res, dp[i]);
- }
- return res;
- }
- public static void main(String[] args) {
- Scanner stdin = new Scanner(System.in);
- int n = stdin.nextInt();
- int a[] = new int[n];
- for (int i = 0; i < a.length; i++) {
- a[i] = stdin.nextInt();
- }
- System.out.println(najdolgaOpagackaSekvenca(a));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement