请教一个算法题

2018-04-02 15:55:21 +08:00
 letianqiu
You are given a map of cities with roads connecting some of them, as well as the length of each road. You have to choose cities in which you will build schools, such that the distance from any city to the nearest city with a school is at most 10 miles, and so that the total number of schools is as small as possible.
题目要求用贪心找出一个解,并证明这个解并不是最优的。
第一反应是求 Minimal Spanning Tree,然后在 Tree 上任意取一个 Vertex,建一个学校,然后把这个节点可以覆盖的 Vertices 去掉,重复,直到没有未覆盖的 Vertex。但是想了以下觉得不对,然后又想是不是对每个 Vertex 作为起点做一次 Dijkstra shortest path,然后每做完一次,从起点建学校,逐步覆盖所有的,然后取所有情况下最优的。无论上述哪一种,都觉得有问题。顺便求教最优解应该怎么求。
1298 次点击
所在节点    程序员
3 条回复
geelaw
2018-04-02 15:59:58 +08:00
考虑一个特殊情况:任意两个直接连接的城市的距离都是 10 miles。此时问题是 minimum dominating set 问题,这是一个 NP-Hard 的问题,因此目前你随便想一个多项式时间的算法都不是最优的。

一个 naïve 的算法是这样的:随便选一个点建立学校,然后删除所有已经被 cover 住的点。
letianqiu
2018-04-02 16:21:46 +08:00
@geelaw 感谢指出 minimum dominating set 问题。不过 NP-Hard 的表述不准确吧,应该是 NP-Complete。
geelaw
2018-04-08 13:08:06 +08:00
@letianqiu 一个问题是 NP-complete 自然代表它是 NP-hard。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/443578

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX