From 1472c454ec38938c8ce1436de6d59c43ce4069ec Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 16 Dec 2022 13:42:29 +0100 Subject: day 16 part 2 --- 22.16/main.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/22.16/main.cpp b/22.16/main.cpp index 9f7641a..62ffe2a 100644 --- a/22.16/main.cpp +++ b/22.16/main.cpp @@ -51,19 +51,23 @@ void findLengths(Graph &g, int base) { Graph g; -int rec(int cur, vector &avail, int time, int score) { +int rec(vector &avail, int time1, int time2, int score = 0, int pos1 = 0, int pos2 = 0) { int best = score; + if (time1 < time2) { + swap(time1, time2); + swap(pos1, pos2); + } for (int i = 0; i < avail.size(); i++) { int n = avail[i]; if (n == 0) continue; - avail[i] = 0; - int time2 = time + g.dist[{cur, n}] + 1; - if (time2 < 30) { - int score2 = score + g.rates[n] * (30 - time2); - best = max(best, rec(n, avail, time2, score2)); + int time1_b = time1 - g.dist[{pos1, n}] - 1; + if (time1_b > 0) { + avail[i] = 0; + int score_b = score + g.rates[n] * time1_b; + best = max(best, rec(avail, time1_b, time2, score_b, n, pos2)); + avail[i] = n; } - avail[i] = n; } return best; } @@ -91,5 +95,6 @@ int main() { for (int base : nonzero) findLengths(g, base); - cout << rec(0, nonzero, 0, 0) << endl; + cout << rec(nonzero, 30, 0) << endl; + cout << rec(nonzero, 26, 26) << endl; } -- cgit 1.4.1-2-gfad0