Convert x - c >= 0 to x >= c since the former will be faster (https://godbolt.org/z/cB0bJm)

This commit is contained in:
Hung Dang 2019-03-28 19:56:33 -04:00
parent 068325b6fa
commit 6a8019e2ca
1 changed files with 3 additions and 3 deletions

View File

@ -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];
}
}