diff options
author | dzwdz | 2022-12-16 13:42:29 +0100 |
---|---|---|
committer | dzwdz | 2022-12-16 13:42:29 +0100 |
commit | 1472c454ec38938c8ce1436de6d59c43ce4069ec (patch) | |
tree | d1eb173a1af16bc9620291c38911ae740ed50af2 | |
parent | 353dfada9165d80eedbc50223b23e813bec401f2 (diff) |
day 16 part 2
-rw-r--r-- | 22.16/main.cpp | 21 |
1 files 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<int> &avail, int time, int score) { +int rec(vector<int> &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; } |