博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4118 Holiday's Accommodation (树形DP 哎,头脑不清晰,没看懂。。。。)
阅读量:6147 次
发布时间:2019-06-21

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

Holiday's Accommodation

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 200000/200000 K (Java/Others)

Total Submission(s): 1457    Accepted Submission(s): 380

Problem Description
Nowadays, people have many ways to save money on accommodation when they are on vacation.
One of these ways is exchanging houses with other people.
Here is a group of N people who want to travel around the world. They live in different cities, so they can travel to some other people's city and use someone's house temporary. Now they want to make a plan that choose a destination for each person. There are 2 rules should be satisfied:
1. All the people should go to one of the other people's city.
2. Two of them never go to the same city, because they are not willing to share a house.
They want to maximize the sum of all people's travel distance. The travel distance of a person is the distance between the city he lives in and the city he travels to. These N cities have N - 1 highways connecting them. The travelers always choose the shortest path when traveling.
Given the highways' information, it is your job to find the best plan, that maximum the total travel distance of all people.
 

 

Input
The first line of input contains one integer T(1 <= T <= 10), indicating the number of test cases.
Each test case contains several lines.
The first line contains an integer N(2 <= N <= 10
5), representing the number of cities.
Then the followingN-1 lines each contains three integersX, Y,Z(1 <= X, Y <= N, 1 <= Z <= 10
6), means that there is a highway between city X and city Y , and length of that highway.
You can assume all the cities are connected and the highways are bi-directional.
 

 

Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y represents the largest total travel distance of all people.
 

 

Sample Input
2 4 1 2 3 2 3 2 4 3 2 6 1 2 3 2 3 4 2 4 1 4 5 8 5 6 5
 

 

Sample Output
Case #1: 18 Case #2: 62
 

 

Source
 

 

Recommend
chenyongfu

 

参看链接: 

转载地址:http://wnmya.baihongyu.com/

你可能感兴趣的文章
9、Dubbo-配置(4)
查看>>
前端第七天
查看>>
图解SSH原理及两种登录方法
查看>>
[转载] 七龙珠第一部——第058话 魔境圣地
查看>>
【总结整理】JQuery基础学习---样式篇
查看>>
查询个人站点的文章、分类和标签查询
查看>>
基础知识:数字、字符串、列表 的类型及内置方法
查看>>
JSP的隐式对象
查看>>
JS图片跟着鼠标跑效果
查看>>
[SCOI2005][BZOJ 1084]最大子矩阵
查看>>
学习笔记之Data Visualization
查看>>
Leetcode 3. Longest Substring Without Repeating Characters
查看>>
数学之美系列二十 -- 自然语言处理的教父 马库斯
查看>>
Android实现自定义位置无标题Dialog
查看>>
面试总结
查看>>
Chrome浏览器播放HTML5音频没声音的解决方案
查看>>
Android源码学习之观察者模式应用
查看>>
416. Partition Equal Subset Sum
查看>>
Django之FBV与CBV
查看>>
Vue之项目搭建
查看>>