hdu4003 树形dp+分组背包
2014-12-21 10:58:02         来源：生活总是充满希望的

Problem Description Humans have discovered a kind of new metal mineral on Mars which are distributed in point‐like with paths connecting each of them which formed a tree. Now Humans launches k robots on Mars to collect them, and due to the unknown reasons, the landing site S of all robots is identified in advanced, in other word, all robot should start their job at point S. Each robot can return to Earth anywhere, and of course they cannot go back to Mars. We have research the information of all paths on Mars, including its two endpoints x, y and energy cost w. To reduce the total energy cost, we should make a optimal plan which cost minimal energy cost.
Input There are 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 robots.
The next n‐1 lines will give three integers x, y, w in each line specifying there is 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.
Output For each cases output one line with the minimal energy cost.
Sample Input
```3 1 1
1 2 1
1 3 1
3 1 2
1 2 1
1 3 1```

Sample Output
```3
2

HintIn the first case: 1->2->1->3 the cost is 3;
In the second case: 1->2; 1->3 the cost is 2;```

```/**
hdu 4003  树形dp+分组背包

对于其中一个顶点，对于它的所有子结点看做一个种类，每一类中包含价值分别为：dp[son][0],dp[son][1]....dp[son][k]重量分别为0~k的物品。

*/
#include
#include
#include
#include
using namespace std;

int n,s,K;

struct note
{
int v,w,next;
}edge[10005*2];

void init()
{
ip=0;
}

{
}

void dfs(int u,int pre)
{
{
int v=edge[i].v;
if(v==pre)continue;
dfs(v,u);
for(int k=K;k>=0;k--)///背包容量枚举
{
dp[u][k]+=dp[v][0]+2*edge[i].w;
for(int j=1;j<=k;j++)///该种类下所有的物品
{
dp[u][k]=min(dp[u][k],dp[u][k-j]+(dp[v][j]+j*edge[i].w));
}
}
}
}
int main()
{
while(~scanf(%d%d%d,&n,&s,&K))
{
init();
for(int i=0;i ```