//---------------------------------------------------------------------------- // CoinChange.java // Implementation of Dynamic Programming for the Coin Change problem. //---------------------------------------------------------------------------- class CoinChange{ static final int INFINITY = 1_000_000; // stand in for infinity, may not // work for large N, or large d[i] public static void main( String[] args ){ int i, j; int N = 15; // value to be paid //int[] d = {0, 1, 2, 5, 7, 9}; // coin system (disregard index 0) int[] d = {0, 2, 4, 6}; int n = d.length-1; // number of coin types int[][] C = new int[n+1][N+1]; // table of optimal subproblem values // Compute C[][] from bottom up // Initialize column 0 for(i=1; i<=n; i++){ C[i][0] = 0; } // Compute rows 1 through n, columns 1 through N for(i=1; i<=n; i++){ for(j=1; j<=N; j++){ if( i==1 && j=INFINITY ){ System.out.println("Amount "+j+" cannot be paid using coins in the set "); PrintCoinSubset(d, i); System.out.println(); }else if( i==1 ){ System.out.println("Pay one coin of type "+d[1]); PrintOptimumCoins(T, d, 1, j-d[1]); }else if( j