HDU 4003——Find Metal Mineral【树形DP & 类树形背包变形】

本博客介绍了一个关于火星上金属矿物收集的问题,其中K个机器人从指定的登陆点出发,需遍历所有由路径连接的矿点。每个路径都有能量消耗,并且机器人可以在任意点返回地球。目标是最小化总能量消耗。通过树形动态规划的方法,求解每个节点处不同数量不返回的机器人完成任务的最小开销,从而找出全局最优解。
摘要由CSDN通过智能技术生成

题目传送门


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


Hint

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


Source

The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest


题意

有K个机器人,走完树上的全部路径,每条路径有个消费。对于一个点,机器人可以出去再回来,开销2倍。也可以不回来,一直停在某个点(如果你的机器人数量足够多的话)。问最小开销。


题解

  • 其实这题只能说是类树形背包。

  • 用dp[i][j]表示在i点,有j个不回来的机器人走过的最小开销。

    比如dp[i][0]就表示,i点及其子点全部靠其它点的不回来的机器人探索。所以机器人是一来一回开销2倍。

    for(K…j…0) //j可以为0

    dp[i][j]+=dp[t][0]+2*e[a].w; //表示子点t全靠其它点的机器人探索

    for(1…k…j) //k要从1开始了,且k最大可以为j,也就是说父亲点可以是0个机器人,子点的机器人下去之后又回到子点,又去探索新的子点的子点。这样必然有父亲点0的情况。

  • 状态转移方程:dp[i][j]=min(dp[i][j],dp[i][j-k]+dp[t][k]+k*e.w);


AC-Code

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值