diff --git a/31 b/31 new file mode 100755 index 0000000..2ee4f5d Binary files /dev/null and b/31 differ diff --git a/31.c b/31.c new file mode 100644 index 0000000..3bdd4d1 --- /dev/null +++ b/31.c @@ -0,0 +1,16 @@ +#include +#include + +int main (int argc, char* argv[]) { + int* ways = calloc (201, sizeof (int)); + ways[0] = 1; + int coins[8] = { 1, 2, 5, 10, 20, 50, 100, 200 }; + for (int c = 0; c < 8; c++) { + for (int w = 0; w <= 200; w++) { + if (w >= coins[c]) { + ways[w] += ways[w - coins[c]]; + } + } + } + printf ("%d\n", ways[200]); +} diff --git a/31_brute b/31_brute new file mode 100755 index 0000000..6da54ee Binary files /dev/null and b/31_brute differ diff --git a/31_brute.c b/31_brute.c new file mode 100644 index 0000000..10b2a76 --- /dev/null +++ b/31_brute.c @@ -0,0 +1,26 @@ +#include +#include + +int main (int argc, char* argv[]) { + int ways = 0; + for (int L2 = 0; L2 <= 1; L2++) { + for (int L1 = 0; L1 <= 2; L1++) { + for (int p50 = 0; p50 <= 4; p50++) { + for (int p20 = 0; p20 <= 10; p20++) { + for (int p10 = 0; p10 <= 20; p10++) { + for (int p5 = 0; p5 <= 40; p5++) { + for (int p2 = 0; p2 <= 100; p2++) { + for (int p1 = 0; p1 <= 200; p1++) { + if (p1 + 2*p2 + 5*p5 + 10*p10 + 20*p20 + 50*p50 + 100*L1 + 200*L2) + ways++; + } + } + } + } + } + } + } + } + + printf ("%d\n", ways); +}