DAG与网格中2个节点之间的查找路径之间的关系

时间:2012-10-16 03:49:11

标签: algorithm graph directed-acyclic-graphs

Hitchhiker的算法指南讨论了以下几点:

1.6 Counting or Optimizing Good Paths
In an n × m grid, we want to go from the left bottom corner to the upper right corner. Each 
time we can only take a step to the right, or a step up. The number of ways we can do this 
is exactly (n+m)!/(n! * m!).  But what if we forbid some points on the grid? For example, if we   
forbid all the points above the line y = x. Some of the problems has answer in closed formula. 
But all of them can be solved quickly by dynamic programming.

Problem 1.6 Given a directed acyclic graph, how many paths are there from u to v? What is the longest one if there are weights on the edges?

我的问题是这两个问题是如何相关的?这里的网格和DAG之间的关系是什么。在stackoverflow本身,我读到如果我们只在网格中的两个方向移动,那么我们可以假设它是一个DAG。这个问题可能听起来很幼稚,但我是初学者,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:2)

网格中的每个点都是一个顶点。你有m * n个顶点。 从每个顶点到顶点有一条边,表示左边的点,从每个顶点到顶点,表示顶部的点。

这样DAG代表网格。