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. FileFilter, FilenameFilter用法和文件排序

    FileFilter和FilenameFilter这两个类的用法都很简单,都只有一个方法 FileFilter /*** @param pathname The abstract pathname t ...

  2. oracle学习----trace文件

    1.查看v$diag_info视图,能查看跟踪文件的位置,具体的名称等信息. name列中,Diag Trace是11g跟踪文件所在位置 Default Trace File是当前会话的跟踪文件名 2 ...

  3. 客户端脚本语言javascript

    2015.11.27  客户端脚本语言javascript. (叫这个名字的原因.想要攀高枝,希望变得和他一样通用.关于名字之间的关系类似于雷锋和雷峰塔,巴基斯坦和卡巴斯基,苏格拉底跟格拉苏蒂的关系一 ...

  4. Quora图片懒加载

    浏览quora的时候发现他的懒加载有点特别,然后就看了一下 然后等图片下载后: 就是上传图片的时候就把图片给压缩成了10X10的小图片,然后加载的时候放大价格模糊的滤镜

  5. LSJ_NHibernate第一章 NHibernate介绍

    前言: 说起NHibernate网上资料真不少,但用的人却并不多,说起java的SSH框架大家可能就知道了,这里的H指的就是Hibernate,一款好用的ORM框架,在.net重写了这款好用的框架,名 ...

  6. 关于MD5校验和java工程下的校验

    File file = new File("cos_code2003.bin"); System.out.println(file.length()); byte[] data = ...

  7. sqlite 数据库打开失败

    今天在做Android电子词典的时候,数据库打不开,报错为:Could not open the database in read/write mode. 后来才发现犯了一个低级错误,没有设置权限. ...

  8. windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法

    windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法: 最近安装完发现8.1系统后,ubuntu无法加载以前的ntfs分区了,特别是我添加到了/etc/fstab里面了 导致 ...

  9. 一、Maven环境搭建(windows 环境)

    所需工具 : JDK 1.7    java 环境 Maven 3.3.9  下载最新版本 Windows 7 注 Maven 3.2 要求 JDK 1.6 或以上版本, 而 Maven 3.0/3. ...

  10. ASP.NET MVC5总结(三)登陆中常用技术解析之session与cookie

    1.session机制 session机制是在服务器端保持状态的方案,在做系统登陆时,我们往往会用到session来存储一些用户登录的重要信息,而这些信息是不能存在cookie中的. 当访问量增多时, ...