最小化覆盖给定间隔集的框数

发布于 2024-08-25 16:54:46 字数 627 浏览 3 评论 0原文

这是算法大师的问题:-)

S 为一组可能重叠的自然数区间,b 为盒子大小。假设对于每个区间,范围严格小于b

我想找到大小为 b 的最小间隔集(我们称之为 M),以便 S 中的所有间隔都包含在间隔中M

简单的例子:

S = {[1..4], [2..7], [3..5], [8..15], [9..13]}
b = 10
M = {[1..10], [8..18]}
// so ([1..4], [2..7], [3..5]) are inside [1..10] and ([8..15], [9..13]) are inside [8..18]

我认为贪婪算法可能并不总是有效,所以如果有人知道这个问题的解决方案(或可以转换成的类似问题),那就太好了。

谢谢!

更新我一直在思考这个问题,也许我的第一直觉是错误的,贪心算法只是解决这个问题的方法,因为最终需要覆盖所有区间并且如何选择超级间隔不会有任何区别......我应该删除这个问题还是也许有人可以断言这一点?

this is a question for the algorithms gurus out there :-)

Let S be a set of intervals of the natural numbers that might overlap and b a box size. Assume that for each interval, the range is strictly less than b.

I want to find the minimum set of intervals of size b (let's call it M) so all the intervals in S are contained in the intervals of M.

Trivial example:

S = {[1..4], [2..7], [3..5], [8..15], [9..13]}
b = 10
M = {[1..10], [8..18]}
// so ([1..4], [2..7], [3..5]) are inside [1..10] and ([8..15], [9..13]) are inside [8..18]

I think a greedy algorithm might not work always, so if anybody knows of a solution to this problem (or a similar one that can be converted into), that would be great.

Thanks!

Update I've been thinking a little bit more about it, and maybe my first intuition was wrong and a greedy algorithm is just the way to solve this, as in the end all the intervals need to be covered and it wouldn't make any difference how the super-intervals are chosen... Should I delete the question or maybe somebody can assert this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的黑色迷你裙 2024-09-01 16:54:46

该算法可能如下。

  1. a = 0
  2. curr = S 中> 的最小数字一个。 (在我们的例子中 = 1. in [1..4])
  3. 向 M 添加一个区间 [curr..b]。(在我们的例子中 M = {[1..10]} )
  4. a = M 中的最大上限。 (在我们的例子中 a = 10 )
  5. 转到 2。

The algorithm might be the following.

  1. a = 0
  2. curr = lowest number in S that is > a. (In our case = 1. in [1..4])
  3. Add an interval [curr..b] to M. (In our case M = {[1..10]} )
  4. a = max upper bound in M. (In our case a = 10 )
  5. Go to 2.
撩发小公举 2024-09-01 16:54:46

是的,贪心算法是最优的。非正式地,考虑任意解 M。我们将其转换为贪婪解 M' 的超集,而不增加间隔的数量。反复考虑 M - M' 中最左边的区间 I。令 s 为 S 中最左边的区间,其中 I 为 M 中包含 s 的最左边区间。从左到右的贪心算法选择一个区间 I',其左边缘与 s 的边缘对齐。我首先声称 I' 在 I 的右侧,因为 I' 是包含 s 的最右边的区间,其次,M - {I} U {I'} 是一个有效的解,因为 I 包含的唯一区间但不是 I' 在 s 的左侧,因此已经包含在其他某个区间中。不在贪婪解中的区间数量减少,因此我们最终达到贪婪解。

Yes, the greedy algorithm is optimal. Informally, consider an arbitrary solution M. We will transform it into a superset of the greedy solution M' without increasing the number of intervals. Repeatedly consider the leftmost interval I in M - M'. Let s be the leftmost interval in S for which I is the leftmost interval in M to contain s. The left-to-right greedy algorithm chooses an interval I' whose left edge is aligned with s's. I claim first that I' is to the right of I, since I' is the rightmost interval to contain s, and second, that M - {I} U {I'} is a valid solution, since the only intervals contained by I but not I' are to the left of s and thus already contained by some other interval. The number of intervals not in the greedy solution decreases, so we eventually reach the greedy solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文