We know that the longest path problem for general case belongs to the NP-hard category, so there is no known polynomial time solution for it. However, for a special case which is directed acyclic graph, we can solve this problem in linear time.

First, take a look at an algorithm that sloves the shortest path problem for DAG in linear time, which makes use of Topological sort.

The only modificaiton to negate the weight of all edges before running this algorithm in order for it to compute a longest path. This algorithm runs in O(V + E) time, its limitation is that it does not allow cycles in the graph.

Solve Longest Path Problem in linear time的更多相关文章

  1. Why longest path problem doesn't have optimal substructure?

    We all know that the shortest path problem has optimal substructure. The reasoning is like below: Su ...

  2. Finding the Longest Palindromic Substring in Linear Time

    Finding the Longest Palindromic Substring in Linear Time Finding the Longest Palindromic Substring i ...

  3. HDU1086You can Solve a Geometry Problem too(判断线段相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  4. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  5. Eclipse 项目红色叹号:Build Path Problem

    Description Resource Path Location TypeA cycle was detected in the build path of project 'shgl-categ ...

  6. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  7. hdu5323 Solve this interesting problem(爆搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Solve this interesting problem Time Limit ...

  8. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

  9. HDU 1086:You can Solve a Geometry Problem too

    pid=1086">You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Mem ...

随机推荐

  1. Java 实现顺序查找

    package search; import java.util.Scanner; /*通常把查找过程中对关键字的平均比较次数,也叫平均查找长度(ASL)作为衡量一个查找算法效率优劣的标准: * AS ...

  2. LSJ_NHibernate第三章 IDAL,DAL,BLL

    前言: 做项目(面向数据编程),首先必须了解业务,这是核心,不懂业务写出来的代码毫无意义.业务我这里分为两种,简单业务操作,复杂业务操作,我以他们操作表的界限进行区分,假设我更新一条数据,只操作了一张 ...

  3. android .9文件的一点处理

    Android上面有很多平台,造成比较严重的碎片问题,适配比较困难,作为应用,一般都需要图文并茂,图片又是比较占资源的.面对缩放的问题,于是出来了矢量图片文件,作一点矢量处理,于是就是.9图片,IOS ...

  4. ACM——大数相加

    大数加法 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte 总提交:2085            测试通过:543 描述 求两个非负整数( ...

  5. LINQ2EF-LINQ2SQL-LINQ笔记

    例1:In SQL: AND dep_all_code LIKE '" + depAll + "' AND dep_code in (SELECT DISTINCT DEP3 FR ...

  6. iOS--NSNetService和NSNetServiceBrowser(Bonjour网络编程)

    Cocoa 网络框架: Cocoa 网络框架有三层,最底层的是基于 BSD socket库,然后是 Cocoa 中基于 C 的 CFNetwork,最上面一层是 Cocoa 中 Bonjour.通常我 ...

  7. Spring配置,JDBC数据源及事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. 工具系列之Sublime Text 3 使用总结

    1.Sublime Text 2/3如何支持中文GBK编码(解决中文乱码)  Sublime Text默认是只支持UTF8的编码,所以有些时候,当我们打开GBK文件时候,文件内会出先部分的乱码,如下图 ...

  9. 颜色空间转换 cvtColor()[OpenCV 笔记13]

    void cvtColor(InputArray src, OutputArray dst, ) src: 输入图像 dst: 输出图像 code: 颜色空间转换标识符 OpenCV2的CV_前缀宏命 ...

  10. 网站开发常用jQuery插件总结(六)关键词说明插件cluetip

    我们开发的网站,总有它一定的用途.如企业站用来宣传企业或展示产品,技术站用来分享自己的思路和经验.既然网站有了它的用途,那么就拥有了它本身的关键词(关键词说明网站的主要内容).例如企业站的关键词大部分 ...