【问题】
想兑换100元钱,有1,2,5,10四种钱,问总共有多少兑换方法。
const int N = 100; int dimes[] = {1, 2, 5, 10}; int arr[N+1] = {1}; int coinExchange(int n) //动态规划 { int i, j; for (i = 0; i < sizeof(dimes)/sizeof(int); i++) { for (j = dimes[i]; j <= n; j++) arr[j] += arr[j-dimes[i]]; } return arr[n]; } int coinExchangeRecursion(int n, int m) //递归 { if (n == 0) return 1; if (n < 0 || m == 0) return 0; return (coinChangeRecursion(n, m-1) + coinChangeRecursion(n-dimes[m-1], m)); }
原文地址:http://blog.csdn.net/jjjcainiao/article/details/38569287