Find Metal Mineral

Time Limit: 1000ms
Memory Limit: 65768KB

This problem will be judged on HDU. Original ID: 4003
64-bit integer IO format: %I64d      Java class name: Main

 
 
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

 
 
解题:传说中的树形dp。。。嗯 待会再讲吧。。。。
 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
struct arc {
int to,w;
};
vector<arc>g[];
int dp[][],n,s,k;
void dfs(int u,int fa){
for(int i = ; i < g[u].size(); i++){
int v = g[u][i].to;
if(v == fa) continue;
dfs(v,u);
for(int t = k; t >= ; t--){
dp[u][t] += dp[v][] + *g[u][i].w;
for(int j = ; j <= t; j++)
dp[u][t] = min(dp[u][t],dp[u][t-j]+dp[v][j]+j*g[u][i].w);
}
}
}
int main(){
while(~scanf("%d%d%d",&n,&s,&k)){
for(int i = ; i <= n; i++)
g[i].clear();
for(int i = ; i < n; i++){
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
g[u].push_back((arc){v,w});
g[v].push_back((arc){u,w});
}
memset(dp,,sizeof(dp));
dfs(s,-);
printf("%d\n",dp[s][k]);
}
return ;
}

xtu summer individual 6 E - Find Metal Mineral的更多相关文章

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

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

  2. hdu 4003 Find Metal Mineral 树形DP

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

  3. HDU4003 Find Metal Mineral 树形DP

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

  4. HDU4003 Find Metal Mineral

    看别人思路的 树形分组背包. 题意:给出结点数n,起点s,机器人数k,然后n-1行给出相互连接的两个点,还有这条路线的价值,要求最小花费 思路:这是我从别人博客里找到的解释,因为很详细就引用了 dp[ ...

  5. hdu 4003 Find Metal Mineral 树形dp ,*****

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

  6. 【树形dp】Find Metal Mineral

    [HDU4003]Find Metal Mineral Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (J ...

  7. 树形DP-----HDU4003 Find Metal Mineral

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

  8. HDOJ 4003 Find Metal Mineral

    题意: 一棵有权树,从根结点中放入 K 个机器人.求用这 K 个机器人遍历全部的结点最少的权值和. 思路: 1. dp[u][i] 表示给以 u 为根节点的子树放 i 个机器人,遍历其子树所须要的最小 ...

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

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

随机推荐

  1. linux自动连接校园网设置

    不知道有没有人用linux的时候碰到过校园网连接后,跳不出登录界面,即使手动输入也没有作用.写一个可能可行的方法: - 首先打开控制面板 选择网络代理 将代理中的选项设置为 估计现在就能自动弹出登录页 ...

  2. Android Dialogs(5)[正常显示dlg,将Fragment显示为dialog,将Aty显示为dlg,嵌入],关闭Dialog

    Showing a Dialog When you want to show your dialog, create an instance of your DialogFragment and ca ...

  3. Android Dialogs(2)最好用DialogFragment创建Dialog

    Creating a Dialog Fragment You can accomplish a wide variety of dialog designs—including custom layo ...

  4. Objective-c单例模式的正确写法--用dispatch 线程安全

    单例模式在iOS开发中可能算是最常用的模式之一了,但是由于oc本身的语言特性,想要写一个正确的单例模式相对来说比较麻烦,这里我就抛砖引玉来聊一聊iOS中单例模式的设计思路.关于单例模式更多的介绍请参考 ...

  5. Java socket1

    注意: 网络编程不是等于网站编程.  html css JavaScript那些是网站编程,是构建在网络编程的基础之上的,网络编程是它的底层.    比方说qq,联动的游戏,这些是网络编程. 一般的网 ...

  6. Oracle用户角色权限相关视图

    常用相关视图概述 DBA_SYS_PRIVS: 查询某个用户所拥有的系统权限 USER_SYS_PRIVS: 当前用户所拥有的系统权限 SESSION_PRIVS: 当前用户所拥有的全部权限 ROLE ...

  7. Web常见几种攻击与预防方式

    DoS和DDoS攻击 DoS(Denial of Service),即拒绝服务,造成远程服务器拒绝服务的行为被称为DoS攻击.其目的是使计算机或网络无法提供正常的服务.最常见的DoS攻击有计算机网络带 ...

  8. jQuery Ajax使用实例

    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script> <scr ...

  9. sql语句添加一列标示,然后进行分页。

    ,) , sum(Score) as Score ,Student_NO,Student_Name into #a2_tab from ksy_stu_ScoreInfo GROUP BY Stude ...

  10. 迅为IMX6核心板开发平台智能交通解决方案

    智能交通系统它是将先进的信息技术.数据通讯传输技术.电子传感技术.控制技术及计算机技术等有效地集成运用于整个地面交通管理系统而建立的一种在大范围内.全方位发挥作用的,实时.准确.高效的综合交通运输管理 ...