kai10k

AoC Day11 Part2 DP

Dec 15th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | Source Code | 0 0
  1. static uint64_t dp(device *d, device *t, cache **kache) {
  2.     if (d == t) {
  3.         return 1;
  4.     } else {
  5.         cache *ca = NULL;
  6.         HASH_FIND(hh, *kache, &d, sizeof(device *), ca);
  7.         if (ca != NULL) {
  8.             return ca->n;
  9.         }
  10.         ca = (cache *)malloc(sizeof(cache));
  11.         ca->n = 0;
  12.         ca->d = d;
  13.         for (int i = 0; i < d->n; i++) {
  14.             device *d0 = d->os[i];
  15.             ca->n += dp(d0, t, kache);
  16.         }
  17.         HASH_ADD(hh, *kache, d, sizeof(device *), ca);
  18.         return ca->n;
  19.     }
  20. }
Tags: aoc
Advertisement
Add Comment
Please, Sign In to add comment