- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有件事让我很烦恼。我正在尝试解决将此信息作为说明的建筑桥梁问题。
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."
我研究了 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 或是否有任何异常(exception)情况不适用于构建桥梁问题?
最佳答案
我的理解是你已经使用最长递增子序列正确地解决了这个问题:
您可以 build 所有 5 座黑色桥梁(但不能 build 2 座红色桥梁)。
为什么你认为你只能造 3 座桥?
关于algorithm - 最长递增子序列解决建筑桥梁问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19469485/
如何判断在现有的 Firebird RDBMS 服务器(即经典服务器或 super 服务器)上安装/配置/运行的架构? 如何在两种模式之间切换? Firebird 的哪些版本(1.5、2.0、2.1)
我很困惑。我有一个运行Ubuntu 14.04的VM。我在这里遵循了以下程序:http://clang.llvm.org/docs/LibASTMatchersTutorial.html,现在正在运行
cli(命令行)这样说: Failed to apply plugin [id 'com.android.library'] Could not create plugin of type 'Libr
我正在尝试构建自己的 gem,但出现了该错误。我认为这是因为我更改了gemspec 的文件名 的原因。首先这是我的结构: myapp/ my-app.gemspec documenta
因此,当我运行我的angular 2应用程序后,我的angular 2应用程序不再起作用。没有错误出现,但是该应用程序不再知道如何路由,因此根据我的index.html,它只是在加载时卡住了。 asa
我正在尝试为Spring Batch 2.1.6构建示例应用程序。 (即spring-batch-2.1.6.RELEASE/samples/spring-batch-samples)使用Maven,
从源代码编译 R-3.3.2。我的标志包括 --with-libtiff。它们是:./configure --with-system-tre --with-blas --with-lapack --w
我正在构建 AOSP,我想用我自己的 key 对构建进行签名。有一些关于此过程的官方文档 here . 但我想知道我是否可以简单地扭转所有流程并改为执行以下操作: 删除位于 build/target/
我可能会问一个愚蠢/基本的问题,但我对 ANTLR AST 构建感到困惑。 我想做的是一种 bool 表达式解析器,这样在父节点上我有运算符及其操作数作为子节点。比如一句话 ( ( A B C & D
我想用“go build”构建我的项目。我还没有找到任何关于如何将 swig 与 go 构建过程集成的文档。而且也很重要,它应该是一个 C++ 示例 C 很容易。 foo.swig /* foo.i
我正在使用 VisualStudio 2013 为 Windows 7 编译 PCL,但我在 include/flann/util/serialization.h 中遇到错误: error C2228
我是一名优秀的程序员,十分优秀!