public class Test60 {
public static int ways4(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++) {
dp[index][rest] =dp[index + 1][rest];
if (rest - arr[index] >= 0) {
dp[index][rest] += dp[index][rest - arr[index]];
}
}
}
return dp[0][aim];
}
}
力扣518.零钱兑换II
最新推荐文章于 2024-09-09 00:44:52 发布