程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> 擴展-Mix and Build

擴展-Mix and Build

編輯:編程解疑
Mix and Build

Description

In this problem, you are given a list of words (sequence of lower case letters). From this list, find the longest chain of words w1, ..., wn such that wi is a mixed extension of wi-1. A word A is a mixed extension of another word B if A can be formed by adding one letter to B and permuting the result. For example, "ab", "bar", "crab", "cobra", and "carbon" form a chain of length 5.
Input

The input contains at least two, but no more than 10000 lines. Each line contains a word. The length of each word is at least 1 and no more than 20. All words in the input are distinct.
Output

Write the longest chain that can be constructed from the given words. Output each word in the chain on a separate line, starting from the first one. If there are multiple longest chains, any longest chain is acceptable.
Sample Input

ab
arc
arco
bar
bran
carbon
carbons
cobra
crab
crayon
narc
Sample Output

ab
bar
crab
cobra
carbon
carbons

最佳回答:


http://blog.csdn.net/sbitswc/article/details/20429853

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved