Skip to content

Commit

Permalink
change font and save tree
Browse files Browse the repository at this point in the history
  • Loading branch information
brianbbsu committed Oct 12, 2023
1 parent 5f8e8a2 commit 1d3cfba
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 45 deletions.
36 changes: 18 additions & 18 deletions codebook/4_Flow_Matching/Model.tex
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
% \normalsize
\begin{itemize}
\itemsep-0.3em
%\itemsep-0.3em
\item Maximum/Minimum flow with lower bound / Circulation problem
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item Construct super source $S$ and sink $T$.
\item For each edge $(x, y, l, u)$, connect $x \rightarrow y$ with capacity $u - l$.
\item For each vertex $v$, denote by $in(v)$ the difference between the sum of incoming lower bounds and the sum of outgoing lower bounds.
\item If $in(v) > 0$, connect $S \rightarrow v$ with capacity $in(v)$, otherwise, connect $v \rightarrow T$ with capacity $-in(v)$.
\begin{itemize}
\itemsep-0.2em
%\itemsep-0.2em
\item To maximize, connect $t \rightarrow s$ with capacity $\infty$ (skip this in circulation problem), and let $f$ be the maximum flow from $S$ to $T$. If $f \neq \sum_{v \in V, in(v) > 0}{in(v)}$, there's no solution. Otherwise, the maximum flow from $s$ to $t$ is the answer.
\item To minimize, let $f$ be the maximum flow from $S$ to $T$. Connect $t \rightarrow s$ with capacity $\infty$ and let the flow from $S$ to $T$ be $f^\prime$. If $f + f^\prime \neq \sum_{v \in V, in(v) > 0}{in(v)}$, there's no solution. Otherwise, $f^\prime$ is the answer.
\end{itemize}
\item The solution of each edge $e$ is $l_e + f_e$, where $f_e$ corresponds to the flow of edge $e$ on the graph.
\end{enumerate}
\item Construct minimum vertex cover from maximum matching $M$ on bipartite graph $(X, Y)$
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item Redirect every edge: $y \rightarrow x$ if $(x, y) \in M$, $x \rightarrow y$ otherwise.
\item DFS from unmatched vertices in $X$.
\item $x \in X$ is chosen iff $x$ is unvisited.
\item $y \in Y$ is chosen iff $y$ is visited.
\end{enumerate}
\item Minimum cost cyclic flow
\vspace{-0.5em}
%\vspace{-0.5em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item Consruct super source $S$ and sink $T$
\item For each edge $(x, y, c)$, connect $x \rightarrow y$ with $(cost, cap) = (c, 1)$ if $c > 0$, otherwise connect $y \rightarrow x$ with $(cost, cap) = (-c, 1)$
\item For each edge with $c < 0$, sum these cost as $K$, then increase $d(y)$ by 1, decrease $d(x)$ by 1
Expand All @@ -37,9 +37,9 @@
\item Flow from $S$ to $T$, the answer is the cost of the flow $C + K$
\end{enumerate}
\item Maximum density induced subgraph
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item Binary search on answer, suppose we're checking answer $T$
\item Construct a max flow model, let $K$ be the sum of all weights
\item Connect source $s \rightarrow v$, $v \in G$ with capacity $K$
Expand All @@ -48,25 +48,25 @@
\item $T$ is a valid answer if the maximum flow $f < K \lvert V \rvert$
\end{enumerate}
\item Minimum weight edge cover
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item For each $v \in V$ create a copy $v^\prime$, and connect $u^\prime \to v^\prime$ with weight $w(u, v)$.
\item Connect $v \to v^\prime$ with weight $2\mu(v)$, where $\mu(v)$ is the cost of the cheapest edge incident to $v$.
\item Find the minimum weight perfect matching on $G^\prime$.
\end{enumerate}
\item Project selection problem
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item If $p_v > 0$, create edge $(s, v)$ with capacity $p_v$; otherwise, create edge $(v, t)$ with capacity $-p_v$.
\item Create edge $(u, v)$ with capacity $w$ with $w$ being the cost of choosing $u$ without choosing $v$.
\item The mincut is equivalent to the maximum profit of a subset of projects.
\end{enumerate}
\item Dual of minimum cost maximum flow
\vspace{-1em}
%\vspace{-1em}
\begin{enumerate}
\itemsep-0.3em
%\itemsep-0.3em
\item Capacity $c_{uv}$, Flow $f_{uv}$, Cost $w_{uv}$, Required Flow difference for vertex $b_u$.
\item If all $w_{uv}$ are integers, then optimal solution can happen when all $p_u$ are integers.
\end{enumerate}
Expand All @@ -76,11 +76,11 @@
\begin{aligned}\min\sum_{u} b_up_u + \sum_{uv}c_{uv}\max(0, p_v - p_u - w_{uv}) \\ p_u \geq 0 \end{aligned}
$$
%\item 0/1 quadratic programming
%\vspace{-1em}
%%\vspace{-1em}
%\[ \sum_x{c_xx} + \sum_y{c_y\bar{y}} + \sum_{xy}c_{xy}x\bar{y} + \sum_{xyx^\prime y^\prime}c_{xyx^\prime y^\prime}(x\bar{y} + x^\prime\bar{y^\prime}) \]
%can be minimized by the mincut of the following graph:
%\begin{enumerate}
% \itemsep-0.3em
% %\itemsep-0.3em
% \item Create edge $(x, t)$ with capacity $c_x$ and create edge $(s, y)$ with capacity $c_y$.
% \item Create edge $(x, y)$ with capacity $c_{xy}$.
% \item Create edge $(x, y)$ and edge $(x^\prime, y^\prime)$ with capacity $c_{xyx^\prime y^\prime}$.
Expand Down
2 changes: 1 addition & 1 deletion codebook/6_Math/Estimation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\item Estimation

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item The number of divisors of $n$ is at most around $100$ for $n<5e4$, $500$ for $n<1e7$, $2000$ for $n<1e10$, $200000$ for $n<1e19$.
\item The number of ways of writing $n$ as a sum of positive integers, disregarding the order of the summands. $1, 1, 2, 3, 5, 7, 11, 15, 22, 30$ for $n=0\sim 9$, $627$ for $n=20$, $\sim 2e5$ for $n=50$, $\sim 2e8$ for $n=100$.
\item Total number of partitions of $n$ distinct elements: $B(n)=1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597,$\\
Expand Down
2 changes: 1 addition & 1 deletion codebook/6_Math/Euclidean.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $m = \lfloor\frac{an + b}{c}\rfloor$
\item Time complexity: $O(\log{n})$
\end{itemize}
Expand Down
6 changes: 3 additions & 3 deletions codebook/6_Math/Generating_function.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\item Ordinary Generating Function
$A(x) = \sum_{i\ge 0} a_ix^i$
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $A(rx) \Rightarrow r^na_n$
\item $A(x) + B(x) \Rightarrow a_n + b_n$
\item $A(x)B(x) \Rightarrow \sum_{i=0}^{n} a_ib_{n-i}$
Expand All @@ -13,7 +13,7 @@
\item Exponential Generating Function
$A(x) = \sum_{i\ge 0} \frac{a_i}{i!}x_i$
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $A(x) + B(x) \Rightarrow a_n + b_n$
\item $A^{(k)}(x) \Rightarrow a_{n+k}$
\item $A(x)B(x) \Rightarrow \sum_{i=0}^{n} \binom{n}{i}a_ib_{n-i}$
Expand All @@ -22,7 +22,7 @@
\end{itemize}
\item Special Generating Function
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $(1+x)^n = \sum_{i\ge 0} \binom{n}{i}x^i$
\item $\frac{1}{(1-x)^n} = \sum_{i\ge 0} \binom{i}{n-1}x^i$
\end{itemize}
Expand Down
6 changes: 3 additions & 3 deletions codebook/6_Math/SimplexConstruction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
$\bar{\mathbf{x}}$ and $\bar{\mathbf{y}}$ are optimal if and only if for all $i \in [1, n]$, either $\bar{x}_i = 0$ or $\sum_{j=1}^{m}A_{ji}\bar{y}_j = c_i$ holds and for all $i \in [1, m]$ either $\bar{y}_i = 0$ or $\sum_{j=1}^{n}A_{ij}\bar{x}_j = b_j$ holds.

\begin{enumerate}
\itemsep-0.5em
%\itemsep-0.5em
\item In case of minimization, let $c^\prime_i = -c_i$
\item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \geq b_j \rightarrow \sum_{1 \leq i \leq n}{-A_{ji}x_i} \leq -b_j$
\item $\sum_{1 \leq i \leq n}{A_{ji}x_i} = b_j$
\vspace{-0.5em}
%\vspace{-0.5em}
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \leq b_j$
\item $\sum_{1 \leq i \leq n}{A_{ji}x_i} \geq b_j$
\end{itemize}
Expand Down
10 changes: 5 additions & 5 deletions codebook/6_Math/Theorem.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

Denote $L$ be a $n \times n$ matrix as the Laplacian matrix of graph $G$, where $L_{ii} = d(i)$, $L_{ij} = -c$ where $c$ is the number of edge $(i, j)$ in $G$.
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item The number of undirected spanning in $G$ is $\lvert \det(\tilde{L}_{11}) \rvert$.
\item The number of directed spanning tree rooted at $r$ in $G$ is $\lvert \det(\tilde{L}_{rr}) \rvert$.
\end{itemize}
Expand All @@ -27,7 +27,7 @@
\item Cayley's Formula

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item Given a degree sequence $d_1, d_2, \ldots, d_n$ for each \textit{labeled} vertices, there are $\frac{(n - 2)!}{(d_1 - 1)!(d_2 - 1)!\cdots(d_n - 1)!}$ spanning trees.
\item Let $T_{n, k}$ be the number of \textit{labeled} forests on $n$ vertices with $k$ components, such that vertex $1, 2, \ldots, k$ belong to different components. Then $T_{n, k} = kn^{n - k - 1}$.
\end{itemize}
Expand All @@ -47,15 +47,15 @@
\item Möbius inversion formula

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $f(n)=\sum_{d\mid n}g(d)\Leftrightarrow g(n)=\sum_{d\mid n}\mu(d)f(\frac{n}{d})$
\item $f(n)=\sum_{n\mid d}g(d)\Leftrightarrow g(n)=\sum_{n\mid d}\mu(\frac{d}{n})f(d)$
\end{itemize}

\item Spherical cap

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item A portion of a sphere cut off by a plane.
\item $r$: sphere radius, $a$: radius of the base of the cap, $h$: height of the cap, $\theta$: $\arcsin(a/r)$.
\item Volume $=\pi h^2(3r-h)/3=\pi h(3a^2+h^2)/6=\pi r^3(2+\cos\theta)(1-\cos\theta)^2/3$.
Expand All @@ -65,7 +65,7 @@
\item Lagrange multiplier

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item Optimize $f(x_1, \ldots, x_n)$ when $k$ constraints $g_i(x_1, \ldots, x_n)=0$.
\item Lagrangian function $\mathcal{L}(x_1, \ldots, x_n, \lambda_1, \ldots, \lambda_k) = f(x_1, \ldots, x_n) = \sum^{k}_{i=1}\lambda_i g_i(x_1, \ldots, x_n)$.
\item The solution corresponding to the original constrained optimization is always a saddle point of the Lagrangian function.
Expand Down
8 changes: 4 additions & 4 deletions codebook/9_Else/Matroid.tex
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Start from $S = \emptyset$. In each iteration, let
\vspace{-0.5em}
%\vspace{-0.5em}
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $Y_1 = \{x \not\in S \mid S \cup \{x\} \in I_1 \}$
\item $Y_2 = \{x \not\in S \mid S \cup \{x\} \in I_2 \}$
\end{itemize}
If there exists $x \in Y_1 \cap Y_2$, insert $x$ into $S$. Otherwise for each $x \in S, y \not\in S$, create edges
\vspace{-0.5em}
%\vspace{-0.5em}
\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item $x \to y$ if $S - \{x\} \cup \{y\} \in I_1$.
\item $y \to x$ if $S - \{x\} \cup \{y\} \in I_2$.
\end{itemize}
Expand Down
4 changes: 2 additions & 2 deletions codebook/9_Else/Mos_Algorithm.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\item Mo's Algorithm With Addition Only

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item Sort querys same as the normal Mo's algorithm.
\item For each query $[l, r]$:
\item If $l / blk = r / blk$, brute-force.
Expand All @@ -14,7 +14,7 @@
\item Mo's Algorithm With Offline Second Time

\begin{itemize}
\itemsep-0.5em
%\itemsep-0.5em
\item Require: Changing answer $\equiv$ adding $f([l, r], r + 1)$.
\item Require: $f([l, r], r + 1) = f([1, r], r + 1) - f([1, l), r + 1)$.
\item Part1: Answer all $f([1, r], r + 1)$ first.
Expand Down
17 changes: 9 additions & 8 deletions codebook/codebook.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
\usepackage{fancyhdr} %設定頁首頁尾
\usepackage{graphicx} %Graphic
\usepackage{enumerate}
\usepackage{multicol}
\usepackage{titlesec}
\usepackage{amsmath}
\usepackage[CheckSingle, CJKmath]{xeCJK}
\usepackage{savetrees}
% \usepackage{CJKulem}

%\usepackage[T1]{fontenc}
Expand All @@ -33,20 +35,17 @@
\evensidemargin=0pt
\hoffset=-42pt

\titlespacing\subsection{0pt}{4pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\section{0pt}{0pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{0pt plus 2pt minus 2pt}{0pt plus 2pt minus 2pt}


%\renewcommand\listfigurename{圖目錄}
%\renewcommand\listtablename{表目錄}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setmainfont{Consolas} %主要字型
%\setmonofont{Monaco} %主要字型
\setmonofont{Consolas}
\setCJKmainfont{Noto Sans CJK TC}
% \setCJKmainfont{Consolas} %中文字型
%\setmainfont{sourcecodepro}
\setmainfont{Ubuntu} %主要字型
\setmonofont{Ubuntu Mono}
\XeTeXlinebreaklocale "zh" %中文自動換行
\XeTeXlinebreakskip = 0pt plus 1pt %設定段落之間的距離
\setcounter{secnumdepth}{3} %目錄顯示第三層
Expand Down Expand Up @@ -125,7 +124,9 @@
\renewcommand{\contentsname}{Contents}

\scriptsize
\tableofcontents
\begin{multicols}{2}
\tableofcontents
\end{multicols}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\newpage
Expand Down

0 comments on commit 1d3cfba

Please sign in to comment.