题目:假设有6中钱币的种类,1,5,10,20,50,100;问由这几种钱币凑成N元的方法有多少种。
import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static long count(int n)
{
int coins[]={1,5,10,20,50,100};
int h = coins.length();
long dp[][] = new dp[h][n+1];
Arrays.fill(dp[0],1);
for(int i=1;i<h;i++)
{
for(int j=1;J<=n;j++)
{
int m = j/coins[i];
for(int k=0;k<=m;k++)
{
dp[i][j] = dp[i][j]+dp[i-1][j-k*cions[i]];
}
}
}
return dp[h-1][n];
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int n = sc.nextInt();
int res = count(n);
System.out.println(res);
}
}
}