dp_longest increasing subsequence

Please design an optimal liberation to find the length of the longest ascending subsequence of the sequence.


public class getLIS {
    public int getLIS(int[] A,int n){
        int[] dp = new int[n];
        int res=0;
        dp[0]=1;
        for(int i=1;i<A.length;i++){
            int max=0,j=0;
            while(j<i){
                if(A[j]<A[i] &&dp[j]>max)
                    max=dp[j];
                j++;
            }
            dp[i]=max+1;
        }
        for(int i=0;i<A.length;i++){
            if(res<dp[i])
                res=dp[i];
        }
        return res;
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324738195&siteId=291194637