There are coins with different nominal values in n. the nominal values of each coin exist in the array T [1. N]. The number of nominal coins that can be used is not limited. Assume that the current sum of money is J, 1 <j <L, to minimize the number of coins.
Solution:
The other C [I, j] represents the minimum number of coins used to redeem J.
# Include "stdafx. H "# include <iostream> # include <fstream> # include <cassert> # define maxvalue 65535 using namespace STD; void making_change (int * t, int ** C, int N, int L) {for (INT I = 1; I <= N; I ++) C [I] [0] = 0; For (Int J = 1; j <+ L; j ++) {If (J % T [1] = 0) C [1] [J] = J/T [1];} for (INT I = 2; I <= N; I ++) {for (Int J = 1; j <= L; j ++) {int M = J/T [I]; for (int K = 0; k <= m; k ++) {If (K + C [I-1] [J-K * t [I]) <C [I] [J]) // recursive formula C [I] [J] = K + C [I-1] [J-K * t [I] ;}}} int _ tmain (INT argc, _ tchar * argv []) {ifstream in ("1.txt"); Assert (in); int N; int L; In> N; in> L; int m; int * t = new int [n + 1]; t [0] = 0; For (INT I = 1; I <= N; I ++) {In> m; t [I] = m;} int ** c = new int * [n + 1]; for (INT I = 0; I <n + 1; I ++) C [I] = new int [L + 1]; for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= L; j ++) C [I] [J] = maxvalue; making_change (T, C, N, L ); for (Int J = 1; j <= L; j ++) {cout <"minimum number of coins with a nominal value of" <j <: "<C [N] [J] <Endl;} return 0 ;}