由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 经典activity selection的问题
相关主题
CLRS 16.1-5 怎么做一道老题
一道面试题——取珠宝一道编程题 晕
Zenefits面经(已挂)看到一个题目
onsite后被拒,怎么回复对方邮件呢?microsoft phone interview round 1
请教一道Google面试题How many full binary trees?
k-selection algorithmgoogle 面试题
突然想起来算一下H-1b 被抽中的概率是多少MS sdet面经 + bloomberg电面面经
google题问个color tree的DP问题
相关话题的讨论汇总
话题: activity话题: selected话题: activities话题: denotes话题: last
进入JobHunting版参与讨论
1 (共1页)
r******n
发帖数: 170
1
一直没弄请怎么解这题,正好从topcoder tutorial上看到有相关讲解:
http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=
不过还是没太清楚,这个伪码里的J=1是怎么选出来的?是直接选结束时间最早的那个
事件吗?记得版上似乎有讨论过,不过没翻出来。哪位知道在哪里吗?
Let N denote the number of activities and
{I} the activity I ( 1 <= I <= N )
For each {I}, consider S[I] and F[I] its starting and finishing time
Sort the activities in the increasing order of their finishing time
- that is, for every I < J we must have F [I] <= F [J]
// A denotes the set of the activities that will be selected
A = {1}
// J denotes the last activity selected
J = 1
For I = 2 to N
// we can select activity 'I' only if the last activity
// selected has already been finished
If S [I] >= F [J]
// select activity 'I'
A = A + {I}
// Activity 'I' now becomes the last activity selected
J = I
Endif
Endfor
Return A
l****3
发帖数: 150
2
当然直接选结束时间最早的那个啊,不然怎么叫贪心?

【在 r******n 的大作中提到】
: 一直没弄请怎么解这题,正好从topcoder tutorial上看到有相关讲解:
: http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=
: 不过还是没太清楚,这个伪码里的J=1是怎么选出来的?是直接选结束时间最早的那个
: 事件吗?记得版上似乎有讨论过,不过没翻出来。哪位知道在哪里吗?
: Let N denote the number of activities and
: {I} the activity I ( 1 <= I <= N )
: For each {I}, consider S[I] and F[I] its starting and finishing time
: Sort the activities in the increasing order of their finishing time
: - that is, for every I < J we must have F [I] <= F [J]
: // A denotes the set of the activities that will be selected

1 (共1页)
进入JobHunting版参与讨论
相关主题
问个color tree的DP问题请教一道Google面试题
请教一下超大图的存储问题k-selection algorithm
请问一道google面试题突然想起来算一下H-1b 被抽中的概率是多少
longest increasing subsequence O(NlogN)算法中数组 P 是否必google题
CLRS 16.1-5 怎么做一道老题
一道面试题——取珠宝一道编程题 晕
Zenefits面经(已挂)看到一个题目
onsite后被拒,怎么回复对方邮件呢?microsoft phone interview round 1
相关话题的讨论汇总
话题: activity话题: selected话题: activities话题: denotes话题: last