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. 题解报告:poj 3061 Subsequence(前缀+二分or尺取法)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  2. VS2010环境下.NET4.0中Tuple<T>的一个小BUG问题

    启动一个桌面程序后,发现一个窗体cfdata=null, 执行时发生错误, 但是在初始化的时候,我明明是cfdata=new Cfdata();为什么会出现这个错误呢. 我开始跟踪,发现当执行cfda ...

  3. 关于k阶裴波那契序列的两种解法

    在学校的anyview的时候,遇到了这个题: [题目]已知k阶裴波那契序列的定义为f(0)=0, f(1)=0, ..., f(k-2)=0, f(k-1)=1;f(n)=f(n-1)+f(n-2)+ ...

  4. C. Mahmoud and a Message dp + 暴力

    http://codeforces.com/contest/766/problem/C 关键在于dp,如何计数. 设dp[i]表示前i个字母中,能分成多少份合法的情况.那么答案就是dp[n],其中dp ...

  5. bootstrap datatable项目封装

    (function($) {     $.fn.formJSON = function() {         var serializeObj = {};         var array = t ...

  6. AJPFX学习笔记JavaAPI之String类

    学习笔记JavaAPI之String类 [size=10.5000pt]一.所属包java.lang.String,没有子类.特点:一旦被初始化就不可以被改变. 创建类对象的两种方式: String ...

  7. Oracle Mysql的jdbc连接

    Oracle和MySql的jdbc或连接池中的连接,写下来以便随时参考 Oracle: driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc ...

  8. [BZOJ1005][HNOI2008]明明的烦恼 数学+prufer序列+高精度

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int N; ...

  9. iOS Programming View and View Hierarchy 视图和视图等级

    iOS Programming  View and View Hierarchy 视图和视图等级 1.1(1)File → New → Project.. From the iOS section, ...

  10. laravel socialite微信登录注意

    在token没有过期之前,重新走登录流程时会跳过callback,即不再重新登录,除了删除了客户端的token