Find Metal Mineral

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 2018    Accepted Submission(s): 913

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
 
题意:
  机器人探索火星,出发点为s。有n的金属矿,k个机器人。
  n-1条线路,满足 x y z   代表  x 到 y 或 y到x    都要花费z的钱。
  求让你遍历所有的点,就是n个金属矿。花费最小。
 
这一题,学到了很多的东西。
题意: 遍历一棵树全部的点,有k个机器人,求最小的消耗。
 
 #include<stdio.h>
#include<stdlib.h>
#include<string.h> int head[],len;
struct node
{
int to;
int next;
int val;
}f[*];
bool use[];
int dp[][],rong; int Min(int x,int y)
{
return x>y? y:x;
}
void add(int x,int y,int w)
{
f[len].to=x;
f[len].val=w;
f[len].next=head[y];
head[y]=len++;
} void dfs(int k)
{
int i,t,K,s;
use[k]=true;
for(i=head[k];i!=-;i=f[i].next)
{
t = f[i].to;
if(use[t]==true) continue;
dfs(t);
for(K=rong;K>=;K--)
{
dp[k][K]+=dp[t][]+*f[i].val;
for(s=;s<=K;s++)
{
dp[k][K]=Min(dp[k][K],dp[k][K-s]+dp[t][s]+(s*f[i].val) );
}
}
}
} int main()
{
int n,s,i;
int x,y,w;
while(scanf("%d%d%d",&n,&s,&rong)>)
{
memset(head,-,sizeof(head));
memset(dp,,sizeof(dp));
memset(use,false,sizeof(use));
len=; for(i=;i<n;i++)
{
scanf("%d%d%d",&x,&y,&w);
add(x,y,w);
add(y,x,w);
}
dfs(s);
printf("%d\n",dp[s][rong]);
}
return ;
}

hdu 4003 Find Metal Mineral 树形dp ,*****的更多相关文章

  1. hdu 4003 Find Metal Mineral 树形DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 Humans have discovered a kind of new metal miner ...

  2. HDU 4003 Find Metal Mineral(分组背包+树形DP)

    题目链接 很棒的一个树形DP.学的太渣了. #include <cstdio> #include <string> #include <cstring> #incl ...

  3. HDU4003Find Metal Mineral[树形DP 分组背包]

    Find Metal Mineral Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Other ...

  4. HDU4003 Find Metal Mineral 树形DP

    Find Metal Mineral Problem Description Humans have discovered a kind of new metal mineral on Mars wh ...

  5. HDU-4003 Find Metal Mineral 树形DP (好题)

    题意:给出n个点的一棵树,有k个机器人,机器人从根节点rt出发,问访问完整棵树(每个点至少访问一次)的最小代价(即所有机器人路程总和),机器人可以在任何点停下. 解法:这道题还是比较明显的能看出来是树 ...

  6. HDU 4003 Find Metal Mineral (树形DP,经典)

    题意:给定一棵树图,n个节点,有边权,要派k<11个机器人从节点s出发,遍历所有的点,每当1只机器人经过1条边时就会花费该边的边权,边是可重复走的.问遍历完所有点的最小花费? 思路: 非常经典, ...

  7. hdu4003Find Metal Mineral(树形DP)

    4003 思维啊 dp[i][j]表示当前I节点停留了j个机器人 那么它与父亲的关系就有了 那条边就走了j遍 dp[i][j] = min(dp[i][j],dp[child][g]+dp[i][j- ...

  8. HDU 4003 Find Metal Mineral

    这个题是POJ1849的加强版. 先说一个很重要的结论,下面两种方法都是从这个结论出发的. 一个人从起点遍历一颗树,如果最终要回到起点,走过的最小权值就是整棵树的权值的2倍. 而且K个人的情况也是如此 ...

  9. hdu 4514 并查集+树形dp

    湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

随机推荐

  1. react.js学习之路六

    学习react中,我一直认为,总组件里面才有构造函数,但是我才发现我的观点是错误的,构造函数是可以出现在子组件里面的. 今天有一个错误是点击增加/减少input框里面 的数值 我一直在寻找input框 ...

  2. CentOS 中卸载 RPM 包文件

    CentOS 中卸载 RPM 包文件 一.原由 因为之前卸载 openvas 这个工具,使用了 find / -name "openvas"-exec rm -rf {} \ ; ...

  3. EXPORT Man Information for Linux use COMMAND col

    col命令 是一个标准输入文本过滤器,它从标注输入设备读取文本内容,并把内容显示到标注输出设备.在许多UNIX说明文件里,都有RLF控制字符.当我们运用shell特殊字符>和>>,把 ...

  4. JMeter—断言

    断言用来对服务器的响应数据做验证,常用的断言是响应断言,支持正则表达式. 一.BeanShell Assertion 用来访问JMeter的属性: log对象,可以利用此对象写日志 SampleRes ...

  5. Corn表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...

  6. P3267 [JLOI2016/SHOI2016]侦察守卫

    $ \color{#0066ff}{ 题目描述 }$ 小R和B神正在玩一款游戏.这款游戏的地图由N个点和N-1条无向边组成,每条无向边连接两个点,且地图是连通的.换句话说,游戏的地图是一棵有N个节点的 ...

  7. 题目1021:统计字符(hash简单应用)

    问题来源 http://ac.jobdu.com/problem.php?pid=1021 问题描述 每次输入两个字符串,统计第一个字符串中的每个字符在第二个字符串中出现的次数. 问题分析 太明显了, ...

  8. 亿级 Elasticsearch 性能优化

    前言 最近一年使用 Elasticsearch 完成亿级别日志搜索平台「ELK」,亿级别的分布式跟踪系统.在设计这些系统的过程中,底层都是采用 Elasticsearch 来做数据的存储,并且数据量都 ...

  9. 日语N5学习

    副词与连接词 ~から: 从-(表示时间.场所起点) ~まで: 到-(表示时间.场所终点) と: 和(并列时用) えーと: 嗯 いっしょに: 一起 ちょっと: 一点儿 いつも: 经常.总是 ときどき: ...

  10. DOM操作 045

    一 什么是DOM DOM : 文档对象模型 它为文档提供了结构化表示 并定义了如何通过脚本来访问文档结构 . 目的就是为了能让js操作HTML元素而制定的一个规范 . DOM树(一切都是节点): 元素 ...