diff options
Diffstat (limited to 'math')
| -rw-r--r-- | math/binomial.cpp | 5 | ||||
| -rw-r--r-- | math/binomial3.cpp | 3 | ||||
| -rw-r--r-- | math/math.tex | 9 |
3 files changed, 12 insertions, 5 deletions
diff --git a/math/binomial.cpp b/math/binomial.cpp index fc6d980..02b27e3 100644 --- a/math/binomial.cpp +++ b/math/binomial.cpp @@ -1,8 +1,7 @@ ll calc_binom(ll n, ll k) { - ll r = 1, d; if (k > n) return 0; - // Reihenfolge garantiert Teilbarkeit - for (d = 1; d <= k; d++) { + ll r = 1; + for (ll d = 1; d <= k; d++) {// Reihenfolge => Teilbarkeit r *= n--; r /= d; } diff --git a/math/binomial3.cpp b/math/binomial3.cpp index 760f2eb..f52337c 100644 --- a/math/binomial3.cpp +++ b/math/binomial3.cpp @@ -1,5 +1,6 @@ ll calc_binom(ll n, ll k, ll p) { - if (n >= p || k > n) return 0; + assert(n < p) //wichtig: sonst falsch! + if (k > n) return 0; ll x = k % 2 != 0 ? p-1 : 1; for (ll c = p-1; c > n; c--) { x *= c - k; x %= p; diff --git a/math/math.tex b/math/math.tex index d648582..3e5e3e0 100644 --- a/math/math.tex +++ b/math/math.tex @@ -388,6 +388,13 @@ so gilt \item Formel $2$ und $3$ erlauben Berechnung in \runtime{n} \end{itemize} +\paragraph{\textsc{Catalan}-Convolution} +\begin{itemize} + \item Anzahl an Klammerausdrücken mit $n+k$ Klammerpaaren, die mit $(^k$ beginnen. +\end{itemize} +\[C^k_0 = 1\qquad C^k_n = \sum\limits_{\mathclap{a_0+a_1+\dots+a_k=n}} C_{a_0}C_{a_1}\cdots C_{a_k} = +\frac{k+1}{n+k+1}\binom{2n+k}{n} = \frac{(2n+k-1)\cdot(2n+k)}{n(n+k+1)} \cdot C_{n-1}\] + \paragraph{\textsc{Euler}-Zahlen 1. Ordnung} Die Anzahl der Permutationen von $\{1, \ldots, n\}$ mit genau $k$ Anstiegen. Für die $n$-te Zahl gibt es $n$ mögliche Positionen zum Einfügen. @@ -453,6 +460,7 @@ Die Anzahl der Partitionen von $n$ mit Elementen aus ${1,\dots,k}$. Die Anzahl der \mbox{$k$-elementigen} Teilmengen einer \mbox{$n$-elementigen} Menge. \textbf{WICHTIG:} Binomialkoeffizient in \runtime{1} berechnen indem man $x!$ vorberechnet. +\columnbreak %\begin{algorithm}{Binomialkoeffizienten} \begin{methods} @@ -463,7 +471,6 @@ Die Anzahl der \mbox{$k$-elementigen} Teilmengen einer \mbox{$n$-elementigen} Me \begin{methods} \method{calc\_binom}{berechnet Binomialkoeffizient modulo Primzahl $p$}{p-n} \end{methods} - \textbf{Wichtig:} $p > n$ \sourcecode{math/binomial3.cpp} \begin{methods} |
