Given the set of intervals, find the minimum number of points that need to be placed so that each interval has a point in it.

Suppose you are given a set of intervals, with the start time of each interval as index s i and the end time f of index i. Find the minimum number of points that need to be placed so that each interval has a point.

I am trying to find an algorithm that would resolve this. I get stuck when a gap that spans two intervals, that is, starts halfway through one interval and ends halfway through another, has an interval that is contained in it.

thank

+3
source share
3 answers
  • , . , , , .
  • s_i.
  • : f_i. , .
  • , , f_i.
  • .
+7
  • .
  • most_recent_placed -inf (- , ).
  • . [a, b], most_recent_placed < a, b most_recent_placed b.

, A , , , B x , B , x, , , x.

+4

First, sort the intervals in ascending order of the starting point. place the dot on the smallest fi. if the next interval, which has the end time f (i + 1), has this point, then the previous point covers f (i + 1), otherwise a new point is put in f (i + 1). Procedure iteration

0
source

Source: https://habr.com/ru/post/1791300/


All Articles