## ramay7

https://ramay7.github.io/

# HDU 4003 Find Metal Mineral(树形dp，从根节点出发k个机器人遍历所有边的最小代价和)

HDU 4003 Find Metal Mineral

dp[u][i]=dp[u][i]+dp[v][0]+cost2

dp[u][i]=min(dp[u][i],dp[u][ij]+dp[v][j]+jcost)

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_N = 10010;
const int MAX_K = 15;

int n, root, total, K;
ll dp[MAX_N][MAX_K];

struct Edge {
int v, w, next;
}edge[MAX_N * 2];

void AddEdge(int u, int v, int w)
{
edge[total].v = v;
edge[total].w = w;
}

void wyr(int u, int p)
{
for (int id = head[u]; id != -1; id = edge[id].next) {
int v = edge[id].v, w = edge[id].w;
if (v == p) continue;
wyr(v, u);
for (int i = K; i >= 0; --i) {
dp[u][i] += dp[v][0] + 2 * w;
for (int j = 1; j <= i; ++j) {
dp[u][i] = min(dp[u][i], dp[v][j] + dp[u][i - j] + j * w);
}
}
}
}

int main()
{
while (~scanf("%d%d%d", &n, &root, &K)) {
total = 0;
for (int i = 1; i < n; ++i) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
}
memset(dp, 0, sizeof(dp));
wyr(root, -1);
printf("%lld\n", dp[root][K]);
}
return 0;
}

#### hdu 4003 Find Metal Mineral 【树形dp，分组背包】

2014-07-25 19:43:08

#### hdu 4003 Find Metal Mineral 树形dp+分组背包

2014-10-02 19:24:03

#### hdu 4003 Find Metal Mineral（树形dp+分组背包）

2016-03-19 10:25:35

#### hdu 4003 Find Metal Mineral (树形背包dp)

2013-08-24 00:30:02

#### E - Strategic Game (HDU - 1054 )(最小顶点覆盖)(匈牙利算法模板)(树形DP)

2017-08-09 10:48:56

#### HDU 4003 Find Metal Mineral （树形dp）

2016-11-01 22:45:42

#### hdu 4003 Find Metal Mineral （树形dp）

2014-03-15 17:03:21

#### hdu 4003 Find Metal Mineral（树形DP）

2014-05-09 15:13:04

#### hdu 4003 Find Metal Mineral 树形DP

2016-05-12 22:23:18

#### HDU 4003 Find Metal Mineral (树形dp）

2016-10-15 22:50:36