Find Metal Mineral
Time limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 3397 Accepted Submission (s): 1588
Problem Descriptionhumans has discovered a kind of new metal mineral on Mars which is distributed in Point‐like with Pat HS connecting each of them which formed a tree. Now humans launches K robots in Mars to collect them, and due to the unknown reasons, the landing site S of all robots are Identified in advanced, in other word, all robot should start their job at point S. Each robot can return to Earth anywhere, and the course they cannot go back to Mars. We have the information of any paths on Mars, including it, endpoints X, Y and energy cost W. To reduce, we should make a optimal plan which cost minimal.
Inputthere is multiple cases in the input.
In each case:
The first line specifies three integers N, S, K specifying the numbers of metal mineral, landing site and the number of RO Bots.
The next n‐1 lines would give three integers x, y, w in each line specifying there are a path connected point x and Y which Should cost W.
1<=n<=10000, 1<=s<=n, 1<=k<=10, 1<=x, Y<=n, 1<=w<=10000.
Outputfor each cases output one line with the minimal energy cost.
Sample INPUT3 1 11 2 11 3 13 1 21 2 11 3 1
Sample Output32
HintIn the first case:1->2->1->3 the 3;in the second case:1->2; 1->3 the cost is 2;
Sourcethe 36th ACM/ICPC Asia Regional Dalian site--online Contest finally pits.As with elective classes, the tree DP, each child node is a grouping, different groups are put on the robot differentF[i][j] Represents the minimum cost of sub-tree I to put J robots (not to come up)f[i][0] means put one again up can be found to put more than the impossible more excellentBecause each group has at least one, so put f[v][0] on the first
////main.cpp//hdu4003////Created by Candy on 9/23/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=1e4+5, m= A;intRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}structedge{intV,w,ne;} E[n<<1];intH[n],cnt=0;voidInsintUintVintW) {CNT++; E[CNT].V=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=CNT; CNT++; E[CNT].V=u;e[cnt].w=w;e[cnt].ne=h[v];h[v]=CNT;}intn,s,m,u,v,w;intF[n][m];voiddpintUintFA) { for(intI=h[u];i;i=e[i].ne) { intv=e[i].v,w=E[I].W; if(V==FA)Continue; DP (V,U); for(intj=m;j>=0; j--) {//ti jif[u][j]+=f[v][0]+w*2;//must choose for(intk=1; k<=j;k++)//GroupF[u][j]=min (f[u][j],f[u][j-k]+f[v][k]+w*k); } }}intMainintargcConst Char*argv[]) { while(cin>>n>>s>>m) {CNT=0; memset (H,0,sizeof(h)); for(intI=1; i<=n-1; i++) {u=read (); V=read (); w=read (); Ins (u,v,w); } memset (F,0,sizeof(f)); DP (S,0); printf ("%d\n", F[s][m]); } return 0;}
Hdu4003find Metal mineral[tree DP Group Backpack]