Dalian Network Competition (HDU 4003 find metal mineral)

Source: Internet
Author: User

Dalian Network Competition (HDU 4003 find metal mineral)

I think this question can be done, but I didn't do it because I didn't see it at the time. Now, if you have time and your status is very good, maybe it can be done,

 

The following code is extracted from the internet. I am not in the status recently, so I am too lazy to think about it. I will put it here for your reference,

/* Question: Put K robots into a right tree from the root node, and use the K robots to traverse and analyze the minimum weights of all nodes: DP [I] [J] indicates the weights and values required by J robots for the subtree with the I node as the root node. When J = 0, it indicates that a robot is put down, and the traversal end point is returned to the I node. The state transition equation is similar to a backpack */# include <stdio. h> # include <string. h> # include <iostream> using namespace STD; const _ int64 maxn = 11000; const _ int64 maxm = 21000; struct edge {_ int64 U, V, W, next;} e [maxm] ;__ int64 edgenum, first [maxn], DP [maxn] [15]; void addedge (_ int64 U ,__ int64 V, __int64 W) {e [edgenum]. U = u, E [edgenum]. V = V, E [edgenum]. W = W, E [edgenum]. next = first [u], first [u] = edgenum ++; E [edgenum]. U = V, E [edgenum]. V = u, E [edgenum]. W = W, E [Ed Genum]. next = first [v], first [v] = edgenum ++;} void DFS (_ int64 t ,__ int64 p) {_ int64 II, I, J, k; For (k = first [T]; k! =-1; k = E [K]. next) {I = E [K]. v; if (I = P) continue; DFS (I, T );} // when first [T] =-1, it indicates that there is only one node in the tree if (first [T] =-1 | (E [first [T]. next =-1 & P! =-1) // leaf node. Be sure to exclude the root node. {For (I = 0; I <= 10; I ++) DP [T] [I] = 0; return;} For (k = first [T]; k! =-1; k = E [K]. next) {I = E [K]. v; if (I = P) continue; For (j = 10; j> = 0; j --) // similar to the 01 backpack, the direction cannot be changed {If (DP [T] [J] =-1) // The first subtree {If (j) {// a maximum of J nodes can be placed in this subtree. You do not have to add all the nodes to this subtree (some robots stop at this node ). Of course, not the best for (II = 1; II <= J; II ++) if (DP [T] [J] =-1 | DP [T] [J]> DP [I] [II] + II * E [K]. w) DP [T] [J] = DP [I] [II] + II * E [K]. w;} else DP [T] [0] = DP [I] [0] + 2 * E [K]. w; continue;} else // otherwise, if the subtree contains 0 robots, DP [T] [J] + = DP [I] [0] + 2 * E [K]. w; For (II = 1; II <= J; II ++) {If (DP [T] [J]> DP [T] [J-II] + dp [I] [II] + II * E [K]. w) DP [T] [J] = DP [T] [J-II] + dp [I] [II] + II * E [K]. W ;}}} int main () {_ int64 N, S, K, I, U, V, W; while (scanf ("% i64d % i64d % i64d", & N, & S, & K )! = EOF) {memset (first,-1, sizeof (first); For (edgenum = 0, I = 1; I <n; I ++) {scanf ("% i64d % i64d % i64d", & U, & V, & W); addedge (U, V, W);} memset (DP,-1, sizeof (DP); DFS (S,-1); printf ("% i64d \ n", DP [s] [k]);} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.