From a816a04d3a260817fe045526743b3b1a1cf4a686 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Thu, 25 May 2017 23:17:28 +0300 Subject: [PATCH] Some fixes --- chapter07.tex | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/chapter07.tex b/chapter07.tex index c4c30b3..7032f21 100644 --- a/chapter07.tex +++ b/chapter07.tex @@ -78,7 +78,7 @@ required to form a sum $x$? Let $\texttt{solve}(x)$ denote the minimum -number of coins required to form a sum $x$. +number of coins required for a sum $x$. The values of the function depend on the values of the coins. For example, if $\texttt{coins} = \{1,3,4\}$, @@ -110,7 +110,7 @@ that its values can be recursively calculated from its smaller values. The idea is to focus on the \emph{first} coin that we choose for the sum. -For example, in the above example, +For example, in the above scenario, the first coin can be either 1, 3 or 4. If we first choose coin 1, the remaining task is to form the sum 9 @@ -131,7 +131,7 @@ because no coins are needed to form an empty sum. For example, \[ \texttt{solve}(10) = \texttt{solve}(7)+1 = \texttt{solve}(4)+2 = \texttt{solve}(0)+3 = 3.\] -Now we are ready to a general recursive function +Now we are ready to give a general recursive function that calculates the minimum number of coins needed to form a sum $x$: \begin{equation*} @@ -236,7 +236,7 @@ After a value of $\texttt{solve}(x)$ has been stored in $\texttt{value}[x]$, it can be efficiently retrieved whenever the function will be called again with the parameter $x$. The time complexity of the algorithm is $O(nk)$, -where the target sum is $n$ and the number of coins is $k$. +where $n$ is the target sum and $k$ is the number of coins. Note that we can also \emph{iteratively} construct the array \texttt{value} using @@ -257,7 +257,7 @@ for (int x = 1; x <= n; x++) { In fact, most competitive programmers prefer this implementation, because it is shorter and has lower constant factors. -In the sequel, we also use iterative implementations +From now on, we also use iterative implementations in our examples. Still, it is often easier to think about dynamic programming solutions @@ -333,7 +333,7 @@ then $\texttt{solve}(5)=6$ and the recursive formula is \end{split} \end{equation*} -In this case, the general recursive function is as follows: +Then, the general recursive function is as follows: \begin{equation*} \texttt{solve}(x) = \begin{cases} 0 & x < 0\\ @@ -394,7 +394,7 @@ possibilities of dynamic programming. Our first problem is to find the \key{longest increasing subsequence} -in an array \texttt{t} of $n$ elements. +in an array of $n$ elements. This is a maximum-length sequence of array elements that goes from left to right, @@ -488,16 +488,16 @@ that ends at position 6 consists of 4 elements. To calculate a value of $\texttt{length}(k)$, we should find a position $i