about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/downloads/csls-programs/multi
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
committerelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
commit562a9a52d599d9a05f871404050968a5fd282640 (patch)
tree7d3305c1252c043bfe246ccc7deff0056aa6b5ab /js/games/nluqo.github.io/~bh/downloads/csls-programs/multi
parent5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff)
downloadtour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz
*
Diffstat (limited to 'js/games/nluqo.github.io/~bh/downloads/csls-programs/multi')
-rw-r--r--js/games/nluqo.github.io/~bh/downloads/csls-programs/multi36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/downloads/csls-programs/multi b/js/games/nluqo.github.io/~bh/downloads/csls-programs/multi
new file mode 100644
index 0000000..53b7be3
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/downloads/csls-programs/multi
@@ -0,0 +1,36 @@
+program multi;
+ {Multinomial expansion problem}
+
+var memo: array [0..4, 0..7] of integer;
+   i,j:  integer;
+
+function t(n,k:integer) : integer;
+
+  function realt(n,k:integer) : integer;
+   {without memoization}
+
+    begin {realt}
+      if k = 0 then
+        realt := 1
+      else
+        if n = 0 then
+          realt := 0
+        else
+          realt := t(n,k-1)+t(n-1,k)
+    end; {realt}
+
+  begin {t}
+    if memo[n,k] < 0 then
+      memo[n,k] := realt(n,k);
+    t := memo[n,k]
+  end; {t}
+
+begin {main program}
+  {initialization}
+  for i := 0 to 4 do
+    for j := 0 to 7 do
+      memo[i,j] := -1;
+
+  {How many terms in (a+b+c+d)^7?}
+  writeln(t(4,7));
+end.