当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2669:Explore the Pirate's Cave

题目描述
Georgia and Bob are now in a pirate's cave. After exploring, they find that there are a lot of rooms in the cave, and these rooms are connected together by some roads. There are two kinds of rooms: one is full of jewellery and connected by only one road (we call this kind of room jewellery-room), and the other is empty but connected by at least two roads. In this cave, all the rooms are connected as a tree.

Now they are in a jewellery-room, and they want to go to all the jewellery-rooms one by one to fetch all the jewellery and then go back to the room where they stay now. Of course they want to walk for the minimum distance to achieve this goal. After exploring, they have drawn the entire map of the cave, and now the map is at Bob' hand. But Bob doesn't want to give the map to Georgia because Georgia always wants to show how clever she is. Bob just tells Georgia the minimum distance between any two jewellery-rooms and asks Georgia to tell him the order of visiting all the jewellery-rooms to achieve the minimum distance. If the order is not unique, Georgia should tell Bob the total number of possible different orders.

Though Georgia is a very clear girl, she thinks that it is difficult for her to solve this problem all by herself. Can you help her?
输入解释
There are multiply test cases. In the first line of each test case, there is an integer N (2 <= N <= 30), which indicates the number of jewellery-rooms (these rooms are numbered from 1 to N). Then comes N lines, each contains N non-negative integers, which are not larger than 100. The i-th integer in the j-th line represents the distance between room i and room j. It is clear that the distance between room i and room i is 0, and that the distance between room i and room j is a positive integer which is equal to the distance between room j and room i.

You may assume that Georgia and Bob are initially in room 1.

A case with N = 0 indicates the end of input, and this line should not be processed.
输出解释
For each test case, output two integers in a single line. These two integers are separated by a single space. The first number is the minimum distance that they should walk to fetch all the jewellery and then go back. The second number is the number of different orders to visit all the jewellery-rooms to accomplish the above purpose.

The number of different orders may be very large, so if this value is not smaller than 2005, you should divide this value by 2005 and just output the remainder value instead.
输入样例
3
0 3 4
3 0 5
4 5 0
0
输出样例
12 2

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2669

最后修改于 2020-10-29T06:38:54+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536