简体   繁体   English

自上而下DP的自下而上DP

[英]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.

相关问题 从上到下到自下而上的算法(DP) - Going from a top-down to a bottom-up algorithm (DP) 何时使用自下而上 DP 何时使用自上而下 DP - when to use bottom-up DP and when to use top-down DP 就时间复杂度而言,自下而上的 DP 解决方案是否优于自上而下? - Is Bottom-up DP solution better than Top-down in terms of Time complexity? 如果记忆是自上而下的深度优先,而 DP 是自下而上的广度优先,那么自上而下的广度优先/自下而上的深度优先等价物是什么? - If memoization is top-down depth-first, and DP is bottom-up breadth-first, what are the top-down breadth-first / bottom-up depth-first equivalents? WA在Scubadiv Spoj(自上而下的DP) - WA in scubadiv spoj (top down dp) 无法将此递归代码记忆到自上而下的 DP 中 - Not able to Memoize this Recursive Code into Top Down DP 通过 DP 打印 mXn 矩阵从左上角到右下角的所有可能路径 - Print all possible paths from top left to bottom right of a mXn matrix by DP 试图用 Python 实现自上而下的 DP,相信缓存不起作用 - Attempting to implement top down DP with Python, believe caching is not working 自下而上法(DP)中斐波那契数列的时间复杂度 - Time Complexity of fibonacci series in Bottom Up approach(DP) DP左上角vs右下角表填充。 什么时候使用? - DP top left vs bottom right table filling. Which to use when?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM