Skip to content

Commit

Permalink
Add Mana Collection to CHT module (#4983)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzsh authored Dec 16, 2024
1 parent 6be1680 commit d682708
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
12 changes: 12 additions & 0 deletions content/5_Plat/Convex_Hull_Trick.problems.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@
"usacoId": "998"
}
},
{
"uniqueId": "usaco-1285",
"name": "Mana Collection",
"url": "http://www.usaco.org/index.php?page=viewproblem2&cpid=1285",
"source": "Platinum",
"difficulty": "Hard",
"isStarred": false,
"tags": ["Bitmask DP", "Convex"],
"solutionMetadata": {
"kind": "internal"
}
},
{
"uniqueId": "joi-17-LongDistanceCoach",
"name": "2017 - Long-Distance Coach",
Expand Down
13 changes: 0 additions & 13 deletions content/extraProblems.json
Original file line number Diff line number Diff line change
Expand Up @@ -1682,19 +1682,6 @@
"usacoId": "1284"
}
},
{
"uniqueId": "usaco-1285",
"name": "Mana Collection",
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1285",
"source": "Platinum",
"difficulty": "N/A",
"isStarred": false,
"tags": ["DP", "Bitmask", "Convex"],
"solutionMetadata": {
"kind": "USACO",
"usacoId": "1285"
}
},
{
"uniqueId": "usaco-1286",
"name": "Subtree Activation",
Expand Down
28 changes: 28 additions & 0 deletions solutions/platinum/usaco-1285.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
id: usaco-1285
source: USACO Platinum 2023 January
title: Mana Collection
author: Daniel Zhu
---

The [official editorial](https://usaco.org/current/data/sol_prob2_platinum_jan23.html)
provides a thorough solution for this problem, but here are a few details to pay attention to.

Doing a Floyd-Warshall at the start of the algorithm is necessary because,
although the bitmask DP enumerates the next *unvisited* node,
it may be optimal or even necessary to go through a node we've already visited in order to get there.

For instance, consider the following adjacency list:
```
1 -> 2
2 -> 1
1 -> 3
```
To get from node 2 to node 3, we **have** to pass through node 1 no matter what.

Also, it may seem more intuitive to define the bitmask DP as `dp[mask][i]`,
where `mask` represents the nodes we've currently visited (in reverse order),
and `i` represents the node we're currently at.

The issue with this definition, however, is that our state has no idea what the final set of visited nodes is,
meaning we have no way of accurately computing the effect of traversing an edge.

0 comments on commit d682708

Please sign in to comment.