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];
}
}
力扣518.零钱兑换II
于 2024-08-23 23:02:42 首次发布