详细思路见:http://blog.csdn.net/vayawu/article/details/52168147
参考代码:
public static void main(String[] args) { int[]coins= {2,8,10,23}; int value=888; int[]solu=new int[value]; int min=new TestCandB().solution(coins,value,solu); for(int i=value-1;i>=0;) { System.out.print(solu[i]+"->"); i=i-solu[i]; } System.out.println("硬币总数:"+min); } private int solution(int[]coins,int value,int[]solu) { int[]mins=new int[value+1]; mins[0]=0; for(int i=1;i<=value;i++) { mins[i]=i; for(int j=0;j<coins.length;j++) { if(coins[j]<=i&&mins[i]>mins[i-coins[j]]+1) { mins[i]=mins[i-coins[j]]+1; solu[i-1]=coins[j]; } } } return mins[value]; }