Domanda

I've something that bothers me. I'm trying to solve building bridge problem which have this information as a instruction.

Building Bridges
Consider a 2-D map with a horizontal river passing through its center. There are n cities on the southern bank with x-coordinates a(1) ... a(n) and n cities on the northern bank with x-coordinates b(1) ... b(n).
You want to connect as many north-south pairs of cities as possible with bridges such that no two bridges cross. When connecting cities, you can only connect city i on the northern bank to city i on the southern bank."

I did research on Stack Overflow and found out some topic that really help me a lot such as:
Building bridges problem - how to apply longest increasing subsequence? and
How to determine the longest increasing subsequence using dynamic programming?

But when I come up with LIS and trying to solve one sample list by hand. Let's say I have

Northern Bank >> 7 4 3 6 2 1 5
Southern Bank >> 5 3 2 4 6 1 7

After sort southern bank

Northern Bank >> 1 3 4 6 7 2 5 
Southern Bank >> 1 2 3 4 5 6 7

Which LIS length suppose to be "5" but actually in the first list, Only 3 bridge are able to create (3,2,1). So did I misunderstand LIS or are there any exception on this that won't work on building bridge problem?

È stato utile?

Soluzione

My understanding is that you have correctly solved the problem using the longest increasing subsequence:

enter image description here

You can build all 5 black bridges (but not the 2 red ones).

Why do you think you can only make 3 bridges?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top