博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4003 Find Metal Mineral 树形dp ,*****
阅读量:5732 次
发布时间:2019-06-18

本文共 2770 字,大约阅读时间需要 9 分钟。

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个机器人,求最小的消耗。
 
1 #include
2 #include
3 #include
4 5 int head[10002],len; 6 struct node 7 { 8 int to; 9 int next;10 int val;11 }f[10003*2];12 bool use[10003];13 int dp[10003][12],rong;14 15 int Min(int x,int y)16 {17 return x>y? y:x;18 }19 void add(int x,int y,int w)20 {21 f[len].to=x;22 f[len].val=w;23 f[len].next=head[y];24 head[y]=len++;25 }26 27 void dfs(int k)28 {29 int i,t,K,s;30 use[k]=true;31 for(i=head[k];i!=-1;i=f[i].next)32 {33 t = f[i].to;34 if(use[t]==true) continue;35 dfs(t);36 for(K=rong;K>=0;K--)37 {38 dp[k][K]+=dp[t][0]+2*f[i].val;39 for(s=1;s<=K;s++)40 {41 dp[k][K]=Min(dp[k][K],dp[k][K-s]+dp[t][s]+(s*f[i].val) );42 }43 }44 }45 }46 47 int main()48 {49 int n,s,i;50 int x,y,w;51 while(scanf("%d%d%d",&n,&s,&rong)>0)52 {53 memset(head,-1,sizeof(head));54 memset(dp,0,sizeof(dp));55 memset(use,false,sizeof(use));56 len=0;57 58 for(i=1;i

 

转载于:https://www.cnblogs.com/tom987690183/p/3407160.html

你可能感兴趣的文章
摘记总结(1)
查看>>
TFS强制撤销某个工作区的文件签出记录
查看>>
编写who命令
查看>>
2.1 sikuli 中编程运行
查看>>
愚公移山第一章伪代码
查看>>
常见的位运算技巧总结(膜wys)
查看>>
python魔法函数(二)之__getitem__、__len__、__iter__
查看>>
EL表达式无法显示Model中的数据
查看>>
Linux应用小技巧
查看>>
考题纠错2
查看>>
ps6-工具的基础使用
查看>>
关于CefSharp.WinForms的学习
查看>>
灵活运用 SQL SERVER FOR XML PATH
查看>>
es 加磁盘扩容
查看>>
linux 参数内核
查看>>
使用Azcopy在Azure上进行HBase的冷热备份还原
查看>>
计组_定点数一位乘_布斯公式
查看>>
linux下使用过的命令总结(未整理完)
查看>>
ES6的一些文章
查看>>
LeetCode 198, 213 House Robber
查看>>