今天在CarrerCup上看到了一个问题,好像还没有好的答复,感觉可以用树形DP来做。
题目连接:http://www.careercup.com/question?id=6285363834257408
问题原文:in a tree any root can have any number of children. Every node has an integer value. Find the maximum length on consecutive number sequence anywhere in the tree. For example if root is 2 and one child is 3, its child is 4 its child is 6 then max length will be 3. I was able to write the code the find of one sequence but when one sequence ends and other starts I was not able to handle that case. I think its hard to do by recursion. Is there any other trick or algorithm for this??
问题翻译:在一颗多叉树上,每个节点都有一个整数值,找到一条最长的路径,路径上的节点整数值连续,路径可以从任意节点开始
分析:如果路径指的都是从父节点到子孙节点,则我们可以用树形DP来做,不妨假设对每个节点都有一个标号(如果标号不是天然存在,则一次DFS可以完成),每个