查找非重叠序列的最大覆盖范围的算法即加权间隔调度概率

如何解决查找非重叠序列的最大覆盖范围的算法即加权间隔调度概率

这是 算法。首先,如果元组数组尚未按此顺序排列,则按其起始位置对其进行排序。我假设从零开始的数组索引。

让我们调用元组ib(i)的开始位置和结束位置e(i),以使其总长度为e(i)-b(i)+1。还要定义一个函数next(i),该函数返回第一个元组的元组列表中的位置,可以显示在元组i的右侧。注意,可以使用二进制搜索在O(log n)的时间内计算next(i):只需将所有元组的起始位置b(i)保留在数组b []中,然后在子数组b [中搜索第一个j i + 1 .. n-1]的b [j]> e(i)。

让我们将f(i)定义为 元组i 或之后 开始的任何不重叠元组的最大覆盖率。由于元组i本身是否处于此最佳集合中,因此我们具有:

f(i) = max(e(i) - b(i) + 1 + f(next(i)), f(i+1)) for 0 <= i < n

我们还有边界条件f(n) = 0

显然,最大可能的覆盖范围由f(0)给出。这很容易计算。在伪C ++中:

int b[] = /* Tuple beginning positions, in nondecreasing order */;
int e[] = /* Tuple end positions */;
int n = /* Number of tuples */;

// Find the array position of the leftmost tuple that begins to the right of
// where tuple i ends.
int next(int i) {
    return upper_bound(b + i + 1, b + n, e[i]);
}

int maxCov[n + 1];    // In practice you should dynamically allocate this

// After running this, maxCov[i] will contain the maximum coverage of any
// nonoverlapping subset of the set of n - i tuples whose beginning positions
// are given by b[i .. n-1] and whose ending points are given by e[i .. n-1].
// In particular, maxCov[0] will be the maximum coverage of the entire set.
void calc() {
    maxCov[n] = 0;
    for (int i = n - 1; i >= 0; --i) {
        maxCov[i] = max(e[i] - b[i] + 1 + maxCov[next(i)], maxCov[i + 1]);
    }
}

循环calc()运行n次,并且每次迭代都会对二进制搜索函数进行一次O(log n)调用upper_bound()

我们可以通过计算f(0)的max()的两个输入,查看哪个实际产生了最大值,记录是否暗示着元组0的存在,然后递归处理该大小,来构造一个实际大小的集合。余数(对应于f(next(0))或f(1))。(如果两个输入相等,那么会有多个最优解,我们可以遵循其中一个。)

解决方法

我有一个问题与寻找最长的非重叠序列的算法非常相似。

到链接的问题,唯一的区别是,而不是找到组代表非重叠元组的 最长序列 ,我需要找到一组非重叠元组代表的 最大覆盖 ,我指的 总和元组的长度
是最大(一 元组的长度last - first + 1给定的定义 元组 中的下一个句子)。

我表示元组的方式与链接问题的方式不同。相反(starting index,length),我将元组表示为(first,last);例如,元组(3,7)表示数字集[3,4,5,6,7]。(即使端点匹配,一个元组也会 另一个元组 重叠
;即,(2,6)并且(6,8) 重叠 ,因此不能同时出现在解决方案中。)

例如,请考虑以下一组元组,排序方式为first

[(0,100),(2,50),(30,150),(60,95),(110,190),(120,(191,200)]

此处设置的最大值将[(0,200)]覆盖101 + 81 + 10 = 192。(请注意,此解决方案中的元组 不重叠 。)

解决这个问题的最简单算法的一个例子是什么,该算法的复杂性是什么?(如果可以在中解决,那就太好了O(N),但目前不知道是否可以解决。)

附录: 回想起来,事实证明,我在这里提出的问题等同于
加权区间调度问题

。这是区间调度问题的特例。

以下@j_random_hacker的答案实际上是加权间隔调度问题的已知解决方案,时间复杂度为O(N log(N))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-