Question: HDU 4003 find Metal Mineral
N mining plants are found on Mars. K robots start to mine from s point, and cost between road sections is given to obtain all the mines at the minimum cost.
Category: tree-like DP + group backpack
Analysis: Conclusion 1: If we start from point I, K robots will return to point I after collecting all the mines with K as the root node, the cost is the sum of the cost of the root node multiplied by K.
For each node, define the State: DP [I] [J] the minimum cost of all the ore in the subtree with I as the root node is adopted by J robots.
State transition equation: DP [Father] [num] = min (DP [Father] [num], DP [Father] [num-K] + dp [child. to] [k] + K * child. CAP );
Num indicates the number of robots on the father node, K indicates the number of robots on the child node, and num-k indicates the number of robots on the father node, except for K robots on the child node.
Note: The initialization during the transfer can be optimized through conclusion 1.
# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <cmath> # include <queue> # include <vector> # include <map> # include <set> # include <string> using namespace STD; # define del (a, B) memset (a, B, sizeof (A) const int n = 10100; struct node {int to; int cap ;}; vector <node> V [N]; int DP [N] [12], vis [N]; /// DP [I] [0] indicates the shortest distance from bottom up DP [I] [1] indicates the shortest distance from bottom up DP [I] [2] indicates shortest Distance int N, s, K; void creat (I NT father) {vis [Father] = 1; for (INT I = 0; I <V [Father]. size (); I ++) {node child = V [Father] [I]; If (vis [child. to] = 1) continue; creat (child. to); For (INT num = K; num> = 0; num --) // note that 0 {DP [Father] [num] + = DP [child. to] [0] + 2 * child. CAP; // maximum result for (Int J = 1; j <= num; j ++) DP [Father] [num] = min (DP [Father] [num], DP [Father] [num-J] + dp [child. to] [J] + J * child. CAP); // send J robots to the V sub-tree and then pass through the edge J times between Father-Child }}int main () {While (~ Scanf ("% d", & N, & S, & K) {for (INT I = 0; I <n-1; I ++) {int x, y, z; scanf ("% d", & X, & Y, & Z); node TMP; TMP. to = Y, TMP. CAP = z; V [X]. push_back (TMP); TMP. to = x; V [Y]. push_back (TMP);} del (VIS, 0); del (DP, 0); creat (s); printf ("% d \ n ", DP [s] [k]); For (INT I = 1; I <= N; I ++) V [I]. clear () ;}return 0 ;}