动态规划。鉴于它是DAG,在最长路径问题中也引用了它。
以下来自Wikipedia的代码:
algorithm dag-longest-path is input: Directed acyclic graph G output: Length of the longest path length_to = array with |V(G)| elements of type int with default value 0 for each vertex v in topOrder(G) do for each edge (v, w) in E(G) do if length_to[w] <= length_to[v] + weight(G,(v,w)) then length_to[w] = length_to[v] + weight(G, (v,w)) return max(length_to[v] for v in V(G))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)