列出了不同的工作,并提供了这些工作的开始时间,结束时间和利润。我们的任务是找到一部分工作,这些工作的利润最大,而且没有工作重叠。
在该算法中,我们使用一个表来存储子问题的结果,并使用子问题的结果,可以自下而上地解决整个问题。
该算法的时间复杂度为O(n ^ 2),但是我们可以通过使用二进制搜索方法搜索冲突的作业将其更改为O(n Log n)。
Input: The start time, finish time and profit of some jobs as matrix form. And number of jobs. Here 4 jobs are present. 3 5 25 1 2 50 6 15 75 2 100 100 Output: The maximum profit 150. The job sequence is job 2, job 4, or job 2, job 1, job 3. for both cases the max profit is 150 here.
findMaxProfit(jobList, n)
输入: 作业列表和作业数。
产出:从工作中获得最大利润。
Begin sort job list according to their ending time define table to store results table[0] := jobList[0].profit for i := 1 to n-1, do addProfit := jobList[i].profit nonConflict := find jobs which is not conflicting with others if any non-conflicting job found, then addProfit := addProfit + table[nonConflict] if addProfit > table[i - 1], then table[i] := addProfit else table[i] := table[i-1] done result := table[n-1] return result End
#include <iostream> #include <algorithm> using namespace std; struct Job { int start, end, profit; }; bool comp(Job job1, Job job2) { return (job1.end < job2.end); } int nonConflictJob(Job jobList[], int i) { //non conflicting job of jobList[i] for (int j=i-1; j>=0; j--) { if (jobList[j].end <= jobList[i-1].start) return j; } return -1; } int findMaxProfit(Job jobList[], int n) { sort(jobList, jobList+n, comp); //sort jobs based on the ending time int *table = new int[n]; //create jon table table[0] = jobList[0].profit; for (int i=1; i<n; i++) { //查找包括当前工作在内的利润 int addProfit = jobList[i].profit; int l = nonConflictJob(jobList, i); if (l != -1) addProfit += table[l]; table[i] = (addProfit>table[i-1])?addProfit:table[i-1]; //find maximum } int result = table[n-1]; delete[] table; //clear table from memory return result; } int main() { Job jobList[] = { {3, 5, 25}, {1, 2, 50}, {6, 15, 75}, {2, 100, 100} }; int n = 4; cout << "The maximum profit: " << findMaxProfit(jobList, n); return 0; }
输出结果
The maximum profit: 150
我需要两个 cron 工作,我真的不确定我做得是否正确。一个骗局作业应该在每 01.01.xxx 01:00 运行一次,另一个应该在每晚 01:00 运行。 这是正确的表达吗?
我希望每天早上9点完成一项任务。我得到了一些有趣的结果。目前我的工作是这样的: 这是怎么回事?这是正确的表达吗?
问题内容: 我正在使用Quartz Job执行特定任务。 我也在我的Main应用程序类中安排它的执行,而我试图完成的工作是不允许同时执行此作业的实例。 因此,调度程序仅应在其先前实例完成后才执行作业。 这是我的工作班级: 因此,在应用程序的主类中,我正在启动调度程序: 如果另一个实例仍在运行,我想阻止调度程序启动第二个MainJob实例… 问题答案: 只需在Job类顶部使用Annotation。
我在应用程序属性文件中设置了一个cron表达式,如下所示: 注释如下, 但是当运行应用程序时,我得到了以下异常。 原因:java.lang.IllegalStateException:遇到无效@计划的方法'报告作业':对于输入字符串:"1W"。 Spring Boot似乎不接受cron表达式中定义的。知道为什么吗?
Hadoop:(ver-1.2.1),(1+8节点集群) 我的用例是,我试图获得执行特定pig脚本所花费的时间,以及从mapreduce的角度来看,这些时间是如何花费的。我需要多次运行pig脚本(比如说100),以获得平均时间。我启用了,这使我在每个udf函数上花费时间作为mapreduce计数器。我还对每个作业报告的其他延迟、内存度量(cpu时间、堆使用率)感兴趣。我可以从jobtracker
我正在开发一个 Spring-MVC 应用程序,其中我使用调度来删除不必要的额外内容。不幸的是,我计划的方法没有触发。谁能告诉我我做错了什么。 这是代码: 我知道参数名称为1周,但我将在3天后删除它。我刚刚复制了代码…:D任何帮助都很好。谢谢
我知道这对terracotta的人来说是不公平的,但是有人尝试过使用Hazelcast在集群环境中使用计划作业吗? 我能想象到的最简单的实现是以下架构: 全局黑泽尔铸造锁,用于确保只有一台服务器启动了 Quartz 配置。 以分布式任务的形式运行实际任务。(这可以在以后完成,目前繁重的计划任务将需要处理触发分布式任务) 一旦持有锁的服务器关闭,另一台服务器就会获得锁。 我相信对于已经拥有Hazel
一、为什么要进行商业授权? 商业授权是软件开发者授权用户将软件用于商业用途的凭证(商业使用权利),即Niushop开源商城系统授权用户将软件用于商业用途的许可凭证,享有使用iushop开源商城系统进行商业运营的合法权利,适合所有正在使用或将要使用Niushop免费商城系统的网商用户选择!未经官方授权许可不得去除网站前后台版权标识,否则官方视为侵权。 二、商业授权有哪些优势? 永久授权,您只需购买一