【发布时间】:2013-10-28 11:13:01
【问题描述】:
我有一些困扰我的事情。我正在尝试解决以这些信息为指导的桥梁问题。
建造桥梁
考虑一个 2-D 地图,其中一条水平河流穿过其中心。南岸有 n 个城市,x 坐标为 a(1) ... a(n),北岸有 n 个城市,x 坐标为 b(1) ... b(n)。
您希望通过桥梁连接尽可能多的南北城市对,以使没有两座桥梁交叉。连接城市时,只能连接北岸i市和南岸i市。”
我对 Stack Overflow 进行了研究,发现了一些对我很有帮助的主题,例如:
Building bridges problem - how to apply longest increasing subsequence?
和
How to determine the longest increasing subsequence using dynamic programming?
但是当我想出 LIS 并尝试手动解决一个示例列表时。假设我有
Northern Bank >> 7 4 3 6 2 1 5
Southern Bank >> 5 3 2 4 6 1 7
南岸排序后
Northern Bank >> 1 3 4 6 7 2 5
Southern Bank >> 1 2 3 4 5 6 7
假设 LIS 长度为“5”,但实际上在第一个列表中,只有 3 个桥能够创建 (3,2,1)。那么我是否误解了LIS,或者有任何例外不适用于构建桥梁问题?
【问题讨论】:
-
您可能已经将 x 坐标与订单索引混淆了。尝试一个 x 坐标为 10、20、...70 的示例,它可能会更明显。
-
谢谢 jwpat7。我确实很困惑。 :D
标签: algorithm dynamic-programming lis