src/com/michaelho/DynamicProgramming/DP1.java
/**
         * The dynamic method used to find the longest length of subsequence. The runtime is O(N^2).
         *
         * @param array The array to be calculated for longest increasing subsequence.
         * @return int The results of calculation.
         * */
The dynamic method used to find the longest length of subsequence.
The dynamic method used to find the longest length of subsequence .
int dpFindLongestLength(int[] array) {
            int max = 1;
            int[] countArr = new int[array.length];
            for (int i = 0; i < array.length; i++) {
                countArr[i] = 1;
                for (int j = 0; j < i; j ++) {
                    if (array[j] < array[i] && countArr[i] < countArr[j] + 1) {
                        countArr[i] = 1 + countArr[j];
                    }
                }
            }
            for (int count : countArr) {
                max = Math.max(count, max);
            }
            return max;
        }
int dpFindLongestLength ( int [ ] array ) { int max = 1 ; int [ ] countArr = new int [ array . length ] ; for ( int i = 0 ; i < array . length ; i ++ ) { countArr [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) { if ( array [ j ] < array [ i ] && countArr [ i ] < countArr [ j ] + 1 ) { countArr [ i ] = 1 + countArr [ j ] ; } } } for ( int count : countArr ) { max = Math . max ( count , max ) ; } return max ; }
The dynamic method used to find the longest length of subsequence.
The dynamic method used to find the longest length of subsequence .
// O(N) // O(N) // O(N)