-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathActivity Selection Problem
More file actions
32 lines (25 loc) · 892 Bytes
/
Activity Selection Problem
File metadata and controls
32 lines (25 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""The following implementation assumes that the activities
are already sorted according to their finish time"""
"""Prints a maximum set of activities that can be done by a
single person, one at a time"""
# n --> Total number of activities
# s[]--> An array that contains start time of all activities
# f[] --> An array that contains finish time of all activities
def printMaxActivities(s, f ):
n = len(f)
print ("The following activities are selected")
# The first activity is always selected
i = 0
print (i,end=' ')
# Consider rest of the activities
for j in range(1, n):
# If this activity has start time greater than
# or equal to the finish time of previously
# selected activity, then select it
if s[j] >= f[i]:
print (j,end=' ')
i = j
# Driver program to test above function
s = [1 , 3 , 0 , 5 , 8 , 5]
f = [2 , 4 , 6 , 7 , 9 , 9]
printMaxActivities(s , f)