-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mana Collection to CHT module (#4983)
- Loading branch information
Showing
3 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |