[英]Bottom Up DP from Top Down DP
I was thinking if there was some generalized way of converting top down Dynamic Programing to Bottom Up Programming. 我在想是否有一些将自上而下的动态编程转换为自下而上编程的通用方法。
Can we think of some mechanism which gives formal way by which top down DP can we converted to bottom up DP. 我们能否想出一些机制,它给出了自上而下的DP可以转换为自下而上DP的正式方式。
NOTE : I am beginner in Dynamic Programing, and few problems I have seen in which a top down approach is converted to bottom up approach are very different. 注意 :我是动态编程的初学者,我所看到的几个问题,其中自顶向下方法转换为自下而上的方法是非常不同的。 So I am not sure if a generalized way is possible.
所以我不确定是否可以采用通用方法。
By generalized I would mean, how should arrays be initialized, what should be size of array and how many dimensions should array have. 通过概括我的意思是,应该如何初始化数组,应该是数组的大小以及数组应该具有多少维度。
The execution of a dynamic program can be viewed as a directed acyclic graph, where each vertex is a subproblem, and arcs indicate that the solution to a particular subproblem was required to compute the solution for another subproblem. 可以将动态程序的执行视为有向非循环图,其中每个顶点是子问题,并且弧表示需要针对特定子问题的解来计算另一个子问题的解。 What a top-down recursive program with memoization is doing is, in essence, topologically sorting the subgraph of this graph reachable from the root problem via depth-first search.
具有memoization的自上而下的递归程序实际上是通过深度优先搜索从拓扑中对从根问题可到达的图形的子图进行拓扑排序。 To convert it to a bottom-up approach, you need to work out a suitable topological order yourself, which will vary from problem to problem.
要将其转换为自下而上的方法,您需要自己制定合适的拓扑顺序,这些顺序因问题而异。
Top Down solution is usually better, because it only solves the necessary subproblems. 自上而下的解决方案通常更好,因为它只解决了必要的子问题。 Converting a bottom up solution to top down is pretty straightforward, you just need to calculate and store the subproblems on-demand instead of precalculating all off them.
将自下而上的解决方案转换为自上而下是非常简单的,您只需按需计算和存储子问题,而不是预先计算所有子问题。 The other way can be tricky, because you need to know which subproblems to solve.
另一种方法可能很棘手,因为您需要知道要解决的子问题。 Depending on the problem, the difficulty of finding the subproblems without inspecting the upper problems can range from easy to impossible.
根据问题,在不检查上层问题的情况下找到子问题的难度可以从容易到不可能。 For example consider the following: you have an infinite colored, weighted graph, and its verticles are colored with 10 colors.
例如,请考虑以下内容:您有一个无限彩色的加权图,其顶点用10种颜色着色。 Whats the distance to the closest blue verticle from a given A verticle.
距离给定A Verticle最近的蓝色垂直的距离是什么。 Solving it up-down is possible, but going bottom-up is impossible as you would need to start from all blue verticles of the graph.
可以向上解决它,但是自下而上是不可能的,因为你需要从图的所有蓝色顶点开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.