POJ 1934 Trip LCA及其所有不重复的串

来源:互联网 发布:淘宝小号购买平台 编辑:程序博客网 时间:2024/05/16 08:29

 

Trip
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1629 Accepted: 372

Description

Alice and Bob want to go on holiday. Each of them has planned a route, which is a list of cities to be visited in a given order. A route may contain a city more than once. 
As they want to travel together, they have to agree on a common route. None wants to change the order of the cities on his or her route or add other cities. Therefore they have no choice but to remove some cities from the route. Of course the common route should be as long as possible. 
There are exactly 26 cities in the region. Therefore they are encoded on the lists as lower case letters from 'a' to 'z'.

Input

The input consists of two lines; the first line is Alice's list, the second line is Bob's list. 
Each list consists of 1 to 80 lower case letters with no spaces inbetween.

Output

The output should contain all routes that meet the conditions described above, but no route should be listed more than once. Each route should be printed on a separate line. There is at least one such non-empty route, but never more than 1000 different ones. Output them in ascending order.

Sample Input

abcabcaaacbacba

Sample Output

ababaabacaabcbaacabaacacaacbaaacbca

Source

CEOI 2003

 

 

原创粉丝点击