diff options
-rw-r--r-- | dp_solver.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/dp_solver.cpp b/dp_solver.cpp index 055990c..3bbb1c2 100644 --- a/dp_solver.cpp +++ b/dp_solver.cpp @@ -66,8 +66,14 @@ int main() { // Set initial value DP[s] = start; + + // Find the optimal solution + int sol = 7200000; for (int i = 0; i < 36000 * max_it; i++) { if (DP[i] != -1) { + if (i / 36000 > sol / 36000) break; + if (DP[i] >= goal && (sol == 7200000 || DP[i] > DP[sol])) sol = i; + // Calculate parameters int it = i / 36000; int MPQ = (i / 3600) % 10, SB = (i / 360) % 10, M = (i / 36) % 10; @@ -150,13 +156,6 @@ int main() { } } - // Find the optimal solution - int sol = 7200000; - for (int i = 0; i < 36000 * max_it; i++) { - if (i / 36000 > sol / 36000) break; - if (DP[i] >= goal && (sol == 7200000 || DP[i] > DP[sol])) sol = i; - } - // Print output if (sol != 7200000) { vector<int> output; |