Skip to content

Commit 06ec39b

Browse files
committed
Frobenius numbers and more
1 parent cccf035 commit 06ec39b

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

‎comprog.pdf‎

1.49 KB
Binary file not shown.

‎comprog.tex‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ \section{Other Algorithms}
707707
\subsection{128-bit Integer}
708708
GCC has a 128-bit integer data type named \texttt{\_\_int128}. Useful
709709
if doing multiplication of 64-bit integers, or something needing a
710-
little more than 64-bits to represent.
710+
little more than 64-bits to represent. There's also
711+
\texttt{\_\_float128}.
711712
\fi
712713

713714
\subsection{Bit Hacks}
@@ -727,6 +728,7 @@ \section{Other Algorithms}
727728
\begin{tabular}{ll}
728729
\#labeled rooted trees & $n^{n-1}$ \\
729730
\#labeled unrooted trees & $n^{n-2}$ \\
731+
\#forests of $k$ rooted trees & $\frac{k}{n}\binom{n}{k}n^{n-k}$ \\
730732
% Kirchoff's theorem
731733
$\sum_{i=1}^n i^2 = n(n+1)(2n+1)/6$ & $\sum_{i=1}^n i^3 = n^2(n+1)^2/4$ \\
732734
$!n = n\times!(n-1)+(-1)^n$ & $!n = (n-1)(!(n-1)+!(n-2))$ \\
@@ -802,10 +804,12 @@ \section{Useful Information}
802804
\begin{myitemize}
803805
\item Dynamic Programming
804806
\begin{itemize}
807+
\item Parsing CFGs: CYK Algorithm
805808
\item Drop a parameter, recover from others
806809
\item Swap answer and a parameter
807-
\item Parsing CFGs: CYK Algorithm
808-
\item Optimizations
810+
\item When grouping: try splitting in two
811+
\item $2^k$ trick
812+
\item When optimizing
809813
\begin{itemize}
810814
\item Convex hull optimization
811815
\begin{itemize}
@@ -993,8 +997,9 @@ \section{Useful Information}
993997
$a,b,c$ has area $\sqrt{s(s-a)(s-b)(s-c)}$ where $s =
994998
\frac{a+b+c}{2}$.
995999
\item \textbf{Pick's theorem:} A polygon on an integer grid
996-
containing $i$ lattice points and having $b$ lattice points on
997-
the boundary has area $i + \frac{b}{2} - 1$.
1000+
strictly containing $i$ lattice points and having $b$ lattice
1001+
points on the boundary has area $i + \frac{b}{2} - 1$. (Nothing
1002+
similar in higher dimensions)
9981003
\item \textbf{Euler's totient:} The number of integers less than
9991004
$n$ that are comprime to $n$ are $n\prod_{p|n}\left(1 - \frac{1}{p}\right)$
10001005
where each $p$ is a distinct prime factor of $n$.
@@ -1016,8 +1021,10 @@ \section{Useful Information}
10161021
\item \textbf{Frobenius Number:} largest number which can't be
10171022
expressed as a linear combination of numbers $a_1,\ldots,a_n$
10181023
with non-negative coefficients. $g(a_1,a_2) = a_1a_2-a_1-a_2$,
1019-
$N(a_1,a_2)=(a_1-1)(a_2-1)/2$. If $f(a_1,a_2,a_3) =
1020-
g(a_1,a_2,a_3) + a_1+a_2+a_3$ then $f(d a_1,d a_2,a_3) = d f(a_1,a_2,a_3)$.
1024+
$N(a_1,a_2)=(a_1-1)(a_2-1)/2$. $g(d\cdot a_1,d\cdot a_2,a_3) =
1025+
d\cdot g(a_1,a_2,a_3) + a_3(d-1)$. An integer $x>\left(\max_i
1026+
a_i\right)^2$ can be expressed in such a way iff.\ $x\ |\
1027+
\mathrm{gcd}(a_1,\ldots,a_n)$.
10211028
\end{itemize}
10221029

10231030
\subsection{Markov Chains}
@@ -1108,7 +1115,7 @@ \section{Useful Information}
11081115
\item How many operations per second? Compare to local machine.
11091116
\item What is the stack size?
11101117
\item How to use printf/scanf with long long/long double?
1111-
\item Is \texttt{\_{}\_{}int128} available?
1118+
\item Are \texttt{\_{}\_{}int128} and \texttt{\_{}\_{}float128} available?
11121119
\item Does MLE give RTE or MLE as a verdict? What about stack overflow?
11131120
\item What is \texttt{RAND\_{}MAX}?
11141121
\item How does the judge handle extra spaces (or missing newlines) in the output?

0 commit comments

Comments
 (0)