给定一个总的钱数,在给定几个固定面值的硬币,请问有多少种组合方法,可以得到总的钱数
package com.Leetcode.动态规划;
public class MoneyAmount {
public static void main(String[] args) {
int totalMoney = 100;
int[] moneys = new int[]{1,2,5};
int result = getTotalNum(totalMoney,moneys);
System.out.println(result);
}
private static int getTotalNum(int totalMoney, int[] moneys) {
int[] dp = new int[totalMoney+1];
dp[0]=1;
for(int money:moneys){
for (int x=money ; x< totalMoney+1 ; x++) {
dp[x] = dp[x]+dp[x-money];
System.out.println(dp[x]);
}
}
return dp[totalMoney];
}
}