Hdu 4003 Tree-shaped dp+ Group Backpack 2011 Dalian Division Network Tournament C

Source: Internet
Author: User

Test instructions: Ask K robots to start at the same point and traverse the minimum cost required for all points

Link: Point Me

Sample INPUT3 1 1//3 points, starting from 1, 1 robots 1 2 each 3 1 2 each 3 1Sample Output32

Transfer equation: Dp[i][j]=min (Dp[i][j],dp[i][j*k],dp[son[i]][k]+len (i,son[i)) *k)

The equation is still relatively good to write, mainly to traverse all the points

Let's examine the first example

1

/  \

/    \

2 3

We sent a robot to 3, then 1 there is no robot, since the need to traverse all the points, you need to 1->2 has traversed, that is, starting from 1, and then return to 1, when no robot can also access the following points

So dp[i][0] means a robot starting from point I, taking a road and then returning to the value of I, then when we push J, we add this value each time, that is, we can guarantee that all the roads go through

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; AtypedefLong Longll; - #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); the Const intmaxn=10010; - intdp[maxn][ One],VAL[MAXN],HEAD[MAXN]; - intN,m,tt,tot; - structEdge + { -     intTo,next,val; +}edge[maxn*2]; A voidAddedge (intUintVintW) at { -edge[tot].to=v; -edge[tot].next=Head[u]; -Edge[tot].val=W; -head[u]=tot++; - } in voidInit () - { tomemset (head,-1,sizeof(head)); +tot=0; -Memset (DP,0,sizeof(DP)); the } * voidDfsintUintpre) $ {Panax Notoginseng      for(inti=head[u];i!=-1; i=edge[i].next) -     { the         intv=edge[i].to; +         if(V==pre)Continue; A DFS (v,u); the          for(intj=m;j>=0; j--) +         { -dp[u][j]+=dp[v][0]+2*Edge[i].val; $              for(intk=1; j-k>=0; k++) $             { -Dp[u][j]=min (dp[u][j],dp[u][j-k]+dp[v][k]+k*edge[i].val); -             } the         } -     }Wuyi } the intMain () - { Wu     inti,j,k; - #ifndef Online_judge AboutFreopen ("1.in","R", stdin); $     #endif -     intSt; -     intA,b,val; -      while(SCANF ("%d%d%d", &n,&st,&m)! =EOF) A     { + init (); the          for(i=1; i<n;i++) -         { $scanf"%d%d%d",&a,&b,&val); the Addedge (a,b,val); the Addedge (b,a,val); the         } theDFS (st,-1); -printf"%d\n", Dp[st][m]); in     } the}

Hdu 4003 Tree-shaped dp+ Group Backpack 2011 Dalian Division Network Tournament C

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.