/*
 * bhutan.C   -- ECS 110   PR
 *
 * Program to count minimum number of strange-valued
 * coins to make change.
 *
 * Shows memoization.
 * 
 *
 */

#include <iostream.h>

const c1 = 1, c2 = 3, c3=8, c4=17;   // Values of the four kinds of coins
const huge = 0x7fffffff;

int min(int a, int b, int c=huge, int d=huge)
{
 int r = a<b? a:b;
 int s = c<d? c:d;
 return r<s? r:s;
}

int NCoins(int n)   // returns smallest number of coins to make n cents
{
 if (n==c1 || n==c2 || n==c3 || n==c4) return 1;
 if (n<1) return huge;
 return 1+min(NCoins(n-c1),NCoins(n-c2),NCoins(n-c3),NCoins(n-c4));
}

int main()
{
 int cents;

 cout << "How many cents? ";
 cin >> cents;
 cout << "Can make " << cents << " using " << NCoins(cents) << " coins\n";
 
 return 0;
}

