Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LDS {
- private static int[] niza;
- static int[] dp;
- static int rec(int idx) {
- if(idx == niza.length - 1) {
- return 1;
- }
- if(dp[idx] != -1) {
- return dp[idx];
- }
- int result = 1;
- for(int i = idx + 1; i < niza.length; i++) {
- if(niza[idx] > niza[i]) {
- result = Math.max(result, rec(i) + 1);
- }
- }
- dp[idx] = result;
- return result;
- }
- private static int najdolgaOpagackaSekvenca(int[] a) {
- niza = new int[a.length];
- niza = a;
- int result = 0;
- dp = new int[a.length];
- for(int i = 0; i < a.length; i++) {
- dp[i] = -1;
- }
- for(int i = 0; i < a.length; i++) {
- result = Math.max(result, rec(i));
- }
- return result;
- }
- 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