Problem with Longest Increasing Subsequence Algorithm
#1
Hello,

I am having trouble with the Longest Increasing Subsequence algorithm. I am using the code from this resource to try to get the longest increasing subsequence. However, the output is not what I am expecting.


Code:
public static int lis(final int[] A)
    {
        int n = A.length;
        int[] dp = new int[n];
        int maxlen = 0;
        for (int i = 0; i < n; i++)
        {
            dp[i] = 1;
            for (int j = 0; j < i; j++)
            {
                if (A[i] > A[j] && dp[i] < dp[j] + 1)
                    dp[i] = dp[j] + 1;
            }
            maxlen = Math.max(maxlen, dp[i]);
        }
        return maxlen;
    }

I would appreciate any help in resolving this issue.

Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  https ssl algorithm entirely in java/script ejonessss 4 18,021 Nov 14, 2016, 15:56 pm
Last Post: blu_people



Users browsing this thread: 1 Guest(s)