力扣518.零钱兑换II

public class Test59 {
    public static int ways3(int[] arr, int aim) {
        if (arr == null || arr.length == 0 || aim < 0) {
            return 0;
        }
        int N = arr.length;
        int[][] dp = new int[N + 1][aim + 1];
        dp[N][0] = 1;
        for (int index = N -1; index >= 0; index--) {
            for (int rest = 0; rest <= aim; rest++) {
                int ways = 0;
                for (int i = 0; i*arr[index] <= rest; i++) {
                    ways += dp[index + 1][rest - i*arr[index]];
                }
                dp[index][rest] = ways;
            }
        }
        return dp[0][aim];
    }
}

你可能感兴趣的:(算法与数据结构入门(java),算法,java,动态规划,leetcode)