From 6a8019e2ca4ac5c5c1847cd4ed3df7d487894236 Mon Sep 17 00:00:00 2001 From: Hung Dang Date: Thu, 28 Mar 2019 19:56:33 -0400 Subject: [PATCH] Convert x - c >= 0 to x >= c since the former will be faster (https://godbolt.org/z/cB0bJm) --- chapter07.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter07.tex b/chapter07.tex index 70fd873..6d11ac0 100644 --- a/chapter07.tex +++ b/chapter07.tex @@ -247,7 +247,7 @@ value[0] = 0; for (int x = 1; x <= n; x++) { value[x] = INF; for (auto c : coins) { - if (x-c >= 0) { + if (x >= c) { value[x] = min(value[x], value[x-c]+1); } } @@ -283,7 +283,7 @@ value[0] = 0; for (int x = 1; x <= n; x++) { value[x] = INF; for (auto c : coins) { - if (x-c >= 0 && value[x-c]+1 < value[x]) { + if ((x >= c) && value[x-c]+1 < value[x]) { value[x] = value[x-c]+1; first[x] = c; } @@ -358,7 +358,7 @@ for $0 \le x \le n$: count[0] = 1; for (int x = 1; x <= n; x++) { for (auto c : coins) { - if (x-c >= 0) { + if (x >= c) { count[x] += count[x-c]; } }