P2515 [HAOI2010] software installation

The meaning of problems

You \ (n-\) possible dependencies have items, items of value \ (V_I \) , weight \ (W_i \) , backpack size \ (m \) , the maximum value of the goods to make the package.

practice

If these dependencies must be sure that the tree, then we can happily be a tree dp.

Here refresher tree dp: set here \ (dp [u] [j ] \) represented by \ (u \) is the root of the subtree are installed with the weight \ (j \) of the maximum value.

Incidentally, when the update of dfs:

\[dp[u][j] = max(dp[u][j - k], dp[v][k])\]

8 shows the code Kankan:

void dfs(int u) {
    for(int i = weight2[u]; i <= m; i++) dp[u][i] = value2[u];
    for(auto v: G2[u]) {
        dfs(v);
        for(int j = m; j >= weight2[u]; j--) {
            for(int k = 0; k <= j - weight2[u]; k++) {
                dp[u][j] = std::max(dp[u][j], dp[u][j - k] + dp[v][k]);
            }
        }
    }
}

Note: Because this is 01 backpack, so in the enumeration \ (j \) still have to reverse the enumeration of the time.


However, this question is not a question of re-P2014. It may appear circular dependency.

In fact, very simple: a ring dependent items, either select all or none of the election, we direct shrunk to a point not to get away?

There: even if the shrink point, built out of the map is not necessarily a tree, probably forest!

The solution is clear that (but I forgot): the establishment of a super source as a root, a root connected with each forest, becomes a tree.

Holistic approach say finished.


Do you think this all?

Confidently pay up, the result is only 10pts: view after point built too bad you shrink!

I originally wrote a new plan is built like an ordinary shrink point as to write, but it is clear that there is a pot: There may be multiple edges.

The tree has not allowed heavy side, or figure out the answer to it all wrong. It is not acceptable.

So we recorded the original father of each point, as long as the different colors, and the father is not 0, then even the edges.

The final answer is \ (DP [S] [m] \) .

Code not to spicy qwq

Guess you like

Origin www.cnblogs.com/Garen-Wang/p/10959625.html