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. bzoj1925 [Sdoi2010] 地精部落【DP】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1925 一个多月前“过”了这道题,还自欺欺人地认为懂了这道题,这直接导致了昨晚多校联测2的T3 ...

  2. Statistics gathering and SQL Tuning Advisor

    1. https://www.pythian.com/blog/statistics-gathering-and-sql-tuning-advisor/ Our monitoring software ...

  3. MYSQL5.7 忘记ROOT密码/初始化ROOT密码

    编辑my.cnf允许空密码登录 [root@7Core ~]# vi /etc/my.cnf #在[mysqld]下加入一行 skip-grant-tables=1 重新启动Mysql服务 [root ...

  4. Linux 之 2>&1

    我们在Linux下经常会碰到nohup command>/dev/null 2>&1 &这样形式的命令.首先我们把这条命令大概分解下首先就是一个nohup表示当前用户和系统 ...

  5. CF949A/950C Zebras

    思路: 贪心乱搞. 实现: #include <bits/stdc++.h> using namespace std; vector<vector<int>> v; ...

  6. 最近面试oracle 数据库的知识点

    1. Oracle跟SQL Server 2005的区别? 宏观上: 1). 最大的区别在于平台,oracle可以运行在不同的平台上,sql server只能运行在windows平台上,由于windo ...

  7. CentOS安装使用vnc进行远程桌面登录

    以下介绍在CentOS 7下安装vncserver并使用vnc-viewer进行登录(使用root权限): 1.运行命令yum install tigervnc-server安装vncserver: ...

  8. leetcode_865. Smallest Subtree with all the Deepest Nodes

    https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/ 给定一颗二叉树,输出包含所有最深叶子结点的最小子树 ...

  9. image和TFRecord互相转换

    关说不练假把式.手上正好有车牌字符的数据集,想把他们写成TFRecord格式,然后读进来,构建一个简单的cnn训练看看.然后发现准确率只有0.0x.随机猜也比这要好点吧.只能一步步检查整个过程.暂时想 ...

  10. hibernate fetch属性

    fetch的属性值有:select(默认值).join.subselect 1)当fetch=”select”时,程序会先查询返回要查询的主体对象,然后根据lazy属性看是否懒加载. 2)当fetch ...