xtu summer individual 6 E - Find Metal Mineral
2024-08-30 17:58:22
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.
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 ;
}
最新文章
- CLR线程概览(下)
- 搭建一个分布式MongoDB鉴权集群
- 第三次作业:caculator
- POJ 1947Rebuilding Roads(树形DP + 01背包)
- PPTP(Point to Point Tunneling Protocol),即点对点隧道协议。
- ubuntu查看端口占用
- 约跑APP测试报告
- javaweb在线预览
- 【Android Api 翻译2】Android Testing(1) 浅尝Android测试的奥秘
- 小白日记38:kali渗透测试之Web渗透-手动漏洞挖掘(四)-文件上传漏洞
- c++一些语法模板
- SuperMapPy 批量拼接 GeoTiff影像
- linux脚本: 后台启动程序并重定向输出信息脚本
- HDU 4118 Holiday&#39;s Accommodation(树形DP)
- python爬虫--爬取某网站电影下载地址
- SQL Server用户自定义数据类型
- (66)Wangdao.com第十一天_JavaScript 数组Array
- Exp3 免杀原理与实践 20164320 王浩
- Python面试题之Python面试题汇总
- React 模板
热门文章
- Apple Tree POJ - 2486
- 题解报告:hdu 4907 Task schedule
- Zygote和System进程的启动过程、Android应用进程启动过程
- NDK(18)eclipse 使用C++ STL
- 【先定一个小目标】Asp.net Core 在IIS上的托管运行
- 【转】【开源下载】基于TCP网络通信的即时聊天系统(IM系统)(c#源码)
- [BZOJ1088][SCOI2005]扫雷Mine DP
- iOS Programming Introduction to Auto Layout 自动布局
- 【PostgreSQL-9.6.3】进程及体系结构
- 基于ANGULAR.JS的下一代WEB应用开发-01-yeoman