-
Notifications
You must be signed in to change notification settings - Fork 0
/
L.tex
54 lines (47 loc) · 1.94 KB
/
L.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
\section{L}%
\label{sec:l}
\begin{frame}
\frametitle{Problem L: Obstacle Course}
\begin{itemize}
\item First solve at 00:57 by \textbf{yeetmoney} (Yamen Almasalmeh and Reggie Frank)
\item Want to know the number of distinct paths through a string
\item We can either go to the next position, or jump forward to the next
same character \textit{at most} $k$ times
\item \textbf{Insight:} this problem lends itself to recursive thinking:
\begin{itemize}
\item ``If I am at index $i$, where could I have come from?''
\item The answer is that you either came from the previous index, or the last index which has the same character
\item Denote by $f(i, j)$ the number of paths ending at index $i$ which jump forward exactly $j$ times
\item Denote by $prev(i)$ the previous location of the character at $i$ (if it exists)
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Problem L: Obstacle Course (continued)}
\begin{itemize}
\item Denote by $f(i, j)$ the number of paths ending at index $i$ which jump forward exactly $j$ times
\item Denote by $prev(i)$ the previous location of the character at $i$ (if it exists)
\item \[
f(i, j) = \begin{cases}
f(i-1, j), & $j = 0$\\
f(i-1, j), & \text{$prev(i)=i-1$ or DNE}\\
f(i-1, j) + f(prev(i), j-1), & \text{otherwise.}
\end{cases}
\]
\item We also have the base case: $f(0, j) = [j=0]$
\item Can solve this recurrence with dynamic programming
\item \textbf{Potential pitfall:} Must handle the base case, and also the special cases of the recurrence
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Problem L: Python Solution, Top-Down DP}
\pyf{Ltop}
\end{frame}
\begin{frame}
\frametitle{Problem L: Python Solution, Top-Down DP (continued)}
\pyf{Ltop1}
\end{frame}
\begin{frame}
\frametitle{Problem L: Python Solution, Bottom-Up DP}
\pyf{Lbot}
\end{frame}