动态规划.最长递增子序列

package com.dk.动态规划.最长递增子序列;

import java.util.Arrays;

public class TestOut {
    public static void main(String[] args) {
        int[] array = {1, 3, 5, 4, 6};
        System.out.println("初始数组为:" + Arrays.toString(array));
        int[] dp = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            dp[i] = 1;
            System.out.println("i=" + i + "时,默认子序列为dp["+i+"]");
            for (int j = 0; j < i; j++) {
                System.out.println("i=" + i + ",j=" + j + ",    array[i]=" + array[i] + ",array[j]=" + array[j]);
                if (array[i] > array[j]) {
                    System.out.println("array[i] > array[j],dp[i]=" + dp[i] + ",dp[j]+1=" + (dp[j] + 1) + ",最大值:" + Math.max(dp[i], dp[j] + 1));
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                    System.out.println("赋值后dp[i]=" + dp[i]);
                }
            }
            System.out.println();
        }
        System.out.println(Arrays.toString(dp));
    }
}

你可能感兴趣的:(算法,动态规划,java,算法)