<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=TADM2E_8.7</id>
		<title>TADM2E 8.7 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=TADM2E_8.7"/>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=TADM2E_8.7&amp;action=history"/>
		<updated>2026-04-30T21:31:06Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=TADM2E_8.7&amp;diff=474&amp;oldid=prev</id>
		<title>Azazel: Created page with &quot;==== 1 ====  # 20 x 1 # 1 x 6 + 14 x 1  # 2 x 6 + 8 x 1  # 3 x 6 + 2 x 1 # 1 x 10 + 10 x 1 # 1 x 10 + 1 x 6 + 4 x 1 # 2 x 10  ==== 2 ====  More generally:  # there is always o...&quot;</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=TADM2E_8.7&amp;diff=474&amp;oldid=prev"/>
				<updated>2016-12-22T14:07:17Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==== 1 ====  # 20 x 1 # 1 x 6 + 14 x 1  # 2 x 6 + 8 x 1  # 3 x 6 + 2 x 1 # 1 x 10 + 10 x 1 # 1 x 10 + 1 x 6 + 4 x 1 # 2 x 10  ==== 2 ====  More generally:  # there is always o...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==== 1 ====&lt;br /&gt;
&lt;br /&gt;
# 20 x 1&lt;br /&gt;
# 1 x 6 + 14 x 1 &lt;br /&gt;
# 2 x 6 + 8 x 1 &lt;br /&gt;
# 3 x 6 + 2 x 1&lt;br /&gt;
# 1 x 10 + 10 x 1&lt;br /&gt;
# 1 x 10 + 1 x 6 + 4 x 1&lt;br /&gt;
# 2 x 10&lt;br /&gt;
&lt;br /&gt;
==== 2 ====&lt;br /&gt;
&lt;br /&gt;
More generally:&lt;br /&gt;
&lt;br /&gt;
# there is always one way of making zero from any set of denominations;&lt;br /&gt;
# there is one way of making any non-zero sum from one denomination provided that the sum is evenly divisible by the denomination;&lt;br /&gt;
# for larger sets of denominations, the number of ways to make a sum S from a set D = { a, b, ... m, n } where Di &amp;lt; Dj for i &amp;lt; j, is the sum of the ways to make S, S - n, ... S - xn from D' = { a, b, c, ... m }.&lt;br /&gt;
&lt;br /&gt;
Implementation in C:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;assert.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 static unsigned&lt;br /&gt;
 make_change (unsigned sum, unsigned *coins, size_t nr_coins)&lt;br /&gt;
   {&lt;br /&gt;
   unsigned **table = malloc (nr_coins * sizeof *table);&lt;br /&gt;
 &lt;br /&gt;
   assert (table != NULL);&lt;br /&gt;
 &lt;br /&gt;
   for (size_t c = 0; c &amp;lt; nr_coins; ++c)&lt;br /&gt;
     {&lt;br /&gt;
     table[c] = malloc ((1 + sum) * sizeof *table[c]);&lt;br /&gt;
 &lt;br /&gt;
     assert (table[c] != NULL);&lt;br /&gt;
 &lt;br /&gt;
     if (c == 0)&lt;br /&gt;
       {&lt;br /&gt;
       /*&lt;br /&gt;
        * No. of ways of making s from coins[0]: 1 if s is evenly divisible by&lt;br /&gt;
        * coins[0], 0 otherwise.&lt;br /&gt;
        */&lt;br /&gt;
       for (unsigned s = 0; s &amp;lt;= sum; ++s)&lt;br /&gt;
         table[0][s] = s % coins[0] == 0;&lt;br /&gt;
       }&lt;br /&gt;
     else&lt;br /&gt;
       {&lt;br /&gt;
       /*&lt;br /&gt;
        * One way of making 0 from { coins[0] .. coins[c] }: the empty set.&lt;br /&gt;
        */&lt;br /&gt;
       table[c][0] = 1;&lt;br /&gt;
 &lt;br /&gt;
       /*&lt;br /&gt;
        * No. of ways of making s from { coins[0] .. coins[c] }: no. of ways of&lt;br /&gt;
        * making s - n * coins[c] for n &amp;gt; 0 and s &amp;gt;= n * coins[c]&lt;br /&gt;
        * from { coins[0] .. coins[c - 1] }&lt;br /&gt;
        */&lt;br /&gt;
       for (unsigned s = 1; s &amp;lt;= sum; ++s)&lt;br /&gt;
         for (unsigned n = 0; n * coins[c] &amp;lt;= s; n ++)&lt;br /&gt;
           table[c][s] += table[c - 1][s - (n * coins[c])];&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
   unsigned rv = table[nr_coins - 1][sum];&lt;br /&gt;
 &lt;br /&gt;
   for (size_t c = 0; c &amp;lt; nr_coins; ++c)&lt;br /&gt;
     free (table[c]);&lt;br /&gt;
 &lt;br /&gt;
   free (table);&lt;br /&gt;
 &lt;br /&gt;
   return rv;&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
 static int&lt;br /&gt;
 cmp_coins (const void *a, const void *b)&lt;br /&gt;
   {&lt;br /&gt;
   return (*(unsigned *) a &amp;gt; *(unsigned *) b)&lt;br /&gt;
        - (*(unsigned *) a &amp;lt; *(unsigned *) b);&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
 int&lt;br /&gt;
 main (int argc, char **argv)&lt;br /&gt;
   {&lt;br /&gt;
   if (argc &amp;lt; 3)&lt;br /&gt;
     exit (EXIT_FAILURE);&lt;br /&gt;
 &lt;br /&gt;
   unsigned sum = atoi (argv[1]);&lt;br /&gt;
 &lt;br /&gt;
   size_t nr_coins = argc - 2;&lt;br /&gt;
 &lt;br /&gt;
   unsigned *coins = malloc (nr_coins * sizeof *coins);&lt;br /&gt;
 &lt;br /&gt;
   assert (coins != NULL);&lt;br /&gt;
 &lt;br /&gt;
   for (int i = 2; i &amp;lt; argc; ++i)&lt;br /&gt;
     coins[i - 2] = atoi (argv[i]);&lt;br /&gt;
 &lt;br /&gt;
   qsort (coins, nr_coins, sizeof *coins, cmp_coins);&lt;br /&gt;
 &lt;br /&gt;
   fprintf (stderr, &amp;quot;%u\n&amp;quot;, make_change (sum, coins, nr_coins));&lt;br /&gt;
&lt;br /&gt;
   free (coins);&lt;br /&gt;
&lt;br /&gt;
   exit (EXIT_SUCCESS);&lt;br /&gt;
   }&lt;/div&gt;</summary>
		<author><name>Azazel</name></author>	</entry>

	</feed>