Redian新闻
>
求助一道FB的高频题non-overlap jobs
avatar
求助一道FB的高频题non-overlap jobs# JobHunting - 待字闺中
y*8
1
先谢谢各位了!
题目是:Given a set of n jobs with [start time, end time, cost] find a
subset so that no 2 jobs overlap and the cost is maximum.
brute force 肯定是不行的了。我知道一个O(N^2)的解答,请问有更好的答案吗?谢谢
了!
avatar
d*n
2
DP吧, 先sort the jobs by end time, if the end time is the same, then by
start time.
Cost[i] = |- Cost[i-1] + JobCost[i] if job i doesn't overalap with previous
jobs
|- Max(Cost[i-1], Cost[j]+ JobCost[i] where j is the closest job
which is not overlapping with job i


【在 y*******8 的大作中提到】
: 先谢谢各位了!
: 题目是:Given a set of n jobs with [start time, end time, cost] find a
: subset so that no 2 jobs overlap and the cost is maximum.
: brute force 肯定是不行的了。我知道一个O(N^2)的解答,请问有更好的答案吗?谢谢
: 了!

avatar
y*8
5
恕我愚钝,请问为什么是按照end time sort呢?

previous
job

【在 d****n 的大作中提到】
: DP吧, 先sort the jobs by end time, if the end time is the same, then by
: start time.
: Cost[i] = |- Cost[i-1] + JobCost[i] if job i doesn't overalap with previous
: jobs
: |- Max(Cost[i-1], Cost[j]+ JobCost[i] where j is the closest job
: which is not overlapping with job i
:

avatar
j*g
6
Mark
avatar
d*n
7
按endtime的话, 当你处理ith job时, 可以通过binarysearch 很快找到最接近的job
which
is not overlapping with ith job。 因为前面i-1个的endtime是递增的。

【在 y*******8 的大作中提到】
: 恕我愚钝,请问为什么是按照end time sort呢?
:
: previous
: job

avatar
y*8
8
学习了,谢谢!!!

job

【在 d****n 的大作中提到】
: 按endtime的话, 当你处理ith job时, 可以通过binarysearch 很快找到最接近的job
: which
: is not overlapping with ith job。 因为前面i-1个的endtime是递增的。

avatar
h*c
9
这个题如果time granualarity 比较coarse的话
比如
[3,5] -> [3,4,5]
[1,7]-> [1,2,3,4,5,6,7]
然后进hash map
有overlap就是weighted graph 的bfs
opinion
avatar
y*8
10
先谢谢各位了!
题目是:Given a set of n jobs with [start time, end time, cost] find a
subset so that no 2 jobs overlap and the cost is maximum.
brute force 肯定是不行的了。我知道一个O(N^2)的解答,请问有更好的答案吗?谢谢
了!
avatar
d*n
11
DP吧, 先sort the jobs by end time, if the end time is the same, then by
start time.
Cost[i] = |- Cost[i-1] + JobCost[i] if job i doesn't overalap with previous
jobs
|- Max(Cost[i-1], Cost[j]+ JobCost[i] where j is the closest job
which is not overlapping with job i


【在 y*******8 的大作中提到】
: 先谢谢各位了!
: 题目是:Given a set of n jobs with [start time, end time, cost] find a
: subset so that no 2 jobs overlap and the cost is maximum.
: brute force 肯定是不行的了。我知道一个O(N^2)的解答,请问有更好的答案吗?谢谢
: 了!

avatar
y*8
14
恕我愚钝,请问为什么是按照end time sort呢?

previous
job

【在 d****n 的大作中提到】
: DP吧, 先sort the jobs by end time, if the end time is the same, then by
: start time.
: Cost[i] = |- Cost[i-1] + JobCost[i] if job i doesn't overalap with previous
: jobs
: |- Max(Cost[i-1], Cost[j]+ JobCost[i] where j is the closest job
: which is not overlapping with job i
:

avatar
j*g
15
Mark
avatar
d*n
16
按endtime的话, 当你处理ith job时, 可以通过binarysearch 很快找到最接近的job
which
is not overlapping with ith job。 因为前面i-1个的endtime是递增的。

【在 y*******8 的大作中提到】
: 恕我愚钝,请问为什么是按照end time sort呢?
:
: previous
: job

avatar
y*8
17
学习了,谢谢!!!

job

【在 d****n 的大作中提到】
: 按endtime的话, 当你处理ith job时, 可以通过binarysearch 很快找到最接近的job
: which
: is not overlapping with ith job。 因为前面i-1个的endtime是递增的。

avatar
h*c
18
这个题如果time granualarity 比较coarse的话
比如
[3,5] -> [3,4,5]
[1,7]-> [1,2,3,4,5,6,7]
然后进hash map
有overlap就是weighted graph 的bfs
opinion
avatar
Q*w
19

job
请教下如果end time有重复值,同一个end time对应不同的cost。。还能二分不?

【在 d****n 的大作中提到】
: 按endtime的话, 当你处理ith job时, 可以通过binarysearch 很快找到最接近的job
: which
: is not overlapping with ith job。 因为前面i-1个的endtime是递增的。

avatar
m*t
20
仔细看了一下文献,这个题目出出来挺坑人的。。。。
http://en.wikipedia.org/wiki/Interval_scheduling
算是 maximum weight independent set 的特殊情形,而且刚刚好有 polynomial time
的解法。。。我觉得没有相关 background 能想出来解法都不错了。。。。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。