diff --git a/chapter07.tex b/chapter07.tex index f1abef3..b37a8a0 100644 --- a/chapter07.tex +++ b/chapter07.tex @@ -348,7 +348,6 @@ to form an empty sum. Otherwise we calculate the sum of all values of the form $\texttt{solve}(x-c)$ where $c$ is in \texttt{coins}. - The following code constructs an array $\texttt{count}$ such that $\texttt{count}[x]$ equals @@ -393,15 +392,13 @@ possibilities of dynamic programming. \index{longest increasing subsequence} -Let us consider the following problem: -Given an array that contains $n$ -numbers, -our task is to find the +Our first problem is to find the \key{longest increasing subsequence} -of the array. -This is a sequence of array elements +in an array \texttt{t} of $n$ elements. +This is a maximum-length +sequence of array elements that goes from left to right, -and each element of the sequence is larger +and each element in the sequence is larger than the previous element. For example, in the array @@ -462,65 +459,81 @@ contains 4 elements: \end{tikzpicture} \end{center} -Let $f(k)$ be the length of the +Let $\texttt{length}(k)$ denote +the length of the longest increasing subsequence that ends at position $k$. -Using this function, the answer to the problem -is the largest of the values -$f(0),f(1),\ldots,f(n-1)$. -For example, in the above array -the values of the function are as follows: +Thus, if we calculate all values of +$\texttt{length}(k)$ where $0 \le k \le n-1$, +we will find out the length of the +longest increasing subsequence. +For example, the values of the function +for the above array are as follows: \[ \begin{array}{lcl} -f(0) & = & 1 \\ -f(1) & = & 1 \\ -f(2) & = & 2 \\ -f(3) & = & 1 \\ -f(4) & = & 3 \\ -f(5) & = & 2 \\ -f(6) & = & 4 \\ -f(7) & = & 2 \\ +\texttt{length}(0) & = & 1 \\ +\texttt{length}(1) & = & 1 \\ +\texttt{length}(2) & = & 2 \\ +\texttt{length}(3) & = & 1 \\ +\texttt{length}(4) & = & 3 \\ +\texttt{length}(5) & = & 2 \\ +\texttt{length}(6) & = & 4 \\ +\texttt{length}(7) & = & 2 \\ \end{array} \] -When calculating the value of $f(k)$, -there are two possibilities how the subsequence -that ends at position $k$ is constructed: -\begin{enumerate} -\item The subsequence -only contains the element at position $k$. In this case $f(k)=1$. -\item The subsequence contains a subsequence -that ends at position $i$ where $i