【发布时间】:2013-12-02 02:41:58
【问题描述】:
我有一个范围列表,每个范围都有相关的成本。一个例子是这样的:
1 to 1 | distance 10
1 to 2 | distance 9
2 to 3 | distance 8
3 to 4 | distance 2
我想在给定范围内构建具有最大距离(称为 L)的范围,条件是每个选择添加“L”的范围必须是“L”的超集。 “L”以一个空范围开始,所以任何东西都是它的超集。
例如,在给定的范围内,
Take the first range [1..1] and then the range [1..2]
which combined gives a distance of 19.
解释:
Since L is originally empty, [1..1] has the greatest distance so it is now L.
L is now [1..1] whose only superset is [1..2] so that is now L.
L is now [1..2] which has no supersets so the greatest possible distance is 10 + 9 = 19.
我很确定这是一个动态规划问题,但我不知道可以使用的递归关系。这是最有效的方法吗?任何人都可以帮忙吗?
【问题讨论】:
-
除非我遗漏了什么,否则在您的示例中建立一个最大距离的范围是微不足道的;你只包括整个范围。我是否缺少其他限制(例如,负距离的可能性)?否则,我认为DP是矫枉过正。
-
正如我的帖子中提到的,条件是“选择添加“L”的每个范围都必须是“L”的超集。”包括整个范围是行不通的。
-
你为什么假设距离最大的基本范围必须是解决方案的一部分?
标签: algorithm range dynamic-programming