摘要: 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 short 阅读全文
posted @ 2014-04-12 07:20 门对夕阳 阅读(333) 评论(0) 推荐(0) 编辑
摘要: We all know that the shortest path problem has optimal substructure. The reasoning is like below:Supppose we have a path p from node u to v, another node t lies on path p: u->t->v ("->" means a path).We claim that u->t is also a shortest path from u to t, and t->v is a short 阅读全文
posted @ 2014-04-12 06:45 门对夕阳 阅读(246) 评论(0) 推荐(0) 编辑
摘要: Problem:此题的做法和 “检查单链表回文” 那道题的骨架是一样的,用 Recursive 的方法,简洁而优雅。参考回文那道题:http://www.cnblogs.com/Antech/p/3847752.htmlCode in Java:public class Solution { ... 阅读全文
posted @ 2014-04-12 03:08 门对夕阳 阅读(356) 评论(0) 推荐(0) 编辑