开发者

"Sling Blade Runner": efficient algorithm to find chain of overlapping movie titles?

This problem is from the archived puzzle from ITA Software, Since the puzzle is retired I guess it is ok to discuss.

How long a chain of overlapping movie titles, like "Live and Let Die Another Day of the Dead Poet's Society", can you find?

I would like to know what is the best approach/algorithm to solve开发者_运维知识库 such puzzle.


This is a graph problem.

First you build a graph, where each vertex represents a movie. There is an edge (a,b) if the movie a end in the same word as the one with which the movie b starts.

Now you want to find the longest path in the graph. This is NP-complete problem, so it doesn't have polynomial solution. (wikipedia)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜