Question: There is a river which flows horizontally through a country. There are N cities on the north side of the river and N cities on
There is a river which flows horizontally through a country. There are N cities on the north side of the river and N cities on the south side of the river. The X coordinates of the N cities on the north side of the river are n1, n2, , nN, and the X coordinates of the N cities on the south side of the river are s1, s2, , sN. Assume that we can only build bridges between cities with the same number; that is, we can only build bridges between cities with coordinates ni and si, where 1 <= i <= N. In this problem, we ask you to determine the maximum number of bridges we can build without any bridges crossing each other. Note that n1 through nN and s1 through sN are both not sorted.
(1) Describe your definition of a subproblem. Use that definition, prove that this problem exhibits optimal substructure. (2) Describe a dynamic-programming algorithm to solve the problem. (3) What is the time complexity of your algorithm?
** Note: There is already a solution to this question on here but the person who answered copied word for word the solution given in the source material. I am hoping that someone can explain it differently, at least in their own words, so that I can better understand. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
