用子区间查找区间的最小覆盖 [英] Finding the minimal coverage of an interval with subintervals

查看:21
本文介绍了用子区间查找区间的最小覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个区间 (a,b) 和多个子区间 {(ai,bi)}i其并集是 (a,b) 的全部.有没有一种有效的方法来选择这些子区间的最小基数子集,它仍然覆盖 (a,b)?

Suppose I have an interval (a,b), and a number of subintervals {(ai,bi)}i whose union is all of (a,b). Is there an efficient way to choose a minimal-cardinality subset of these subintervals which still covers (a,b)?

推荐答案

从 a 或 b 开始的贪心算法总是给出最优解.

A greedy algorithm starting at a or b always gives the optimal solution.

证明:考虑覆盖a的所有子区间的集合Sa.显然,其中之一必须属于最优解.如果我们用右端点 bmax 的 Sa 的子区间 (amax,bmax) 替换它在 Sa 中最大(到达最右边),剩余的未覆盖区间 (bmax,b) 将是最优解的剩余区间的子集,所以它不能被比最优解的类似未覆盖区间更多的子区间覆盖.因此,由 (amax,bmax) 和剩余区间 (bmax,b) 的最优解构成的解也将是最优的.

Proof: consider the set Sa of all the subintervals covering a. Clearly, one of them has to belong to the optimal solution. If we replace it with a subinterval (amax,bmax) from Sa whose right endpoint bmax is maximal in Sa (reaches furthest to the right), the remaining uncovered interval (bmax,b) will be a subset of the remaining interval from the optimal solution, so it can be covered with no more subintervals than the analogous uncovered interval from the optimal solution. Therefore, a solution constructed from (amax,bmax) and the optimal solution for the remaining interval (bmax,b) will also be optimal.

所以,只需从 a 开始,然后迭代地选择到达最右边的区间(并覆盖前一个区间的末尾),重复直到你点击 b.我相信如果您将区间存储在扩充区间树中,则可以在 log(n) 中选择下一个区间.

So, just start at a and iteratively pick the interval reaching furthest right (and covering the end of previous interval), repeat until you hit b. I believe that picking the next interval can be done in log(n) if you store the intervals in an augmented interval tree.

这篇关于用子区间查找区间的最小覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆