CF1584F.Strange LCS

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn strings s1,s2,,sns_1, s_2, \ldots, s_n , each consisting of lowercase and uppercase English letters. In addition, it's guaranteed that each character occurs in each string at most twice. Find the longest common subsequence of these strings.

A string tt is a subsequence of a string ss if tt can be obtained from ss by deletion of several (possibly, zero or all) symbols.

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t51 \leq t \leq 5 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn ( 2n102 \leq n \leq 10 ) — the number of strings.

Each of the next nn lines contains the corresponding string sis_i . Each sis_i is non-empty, consists only of uppercase and lowercase English letters, and no character appears more than twice in each string.

输出格式

For each test case print the answer in two lines:

In the first line print the length of the longest common subsequence.

In the second line print the longest common subsequence. If there are multiple such subsequences, print any of them.

输入输出样例

  • 输入#1

    4
    2
    ABC
    CBA
    2
    bacab
    defed
    3
    abcde
    aBcDe
    ace
    2
    codeforces
    technocup

    输出#1

    1
    A
    0
    
    3
    ace
    3
    coc

说明/提示

In the first test case, the longest common subsequence is "A". There are no common subsequences of length 22 .

In the second test case, sets of characters of strings don't intersect, so any non-empty string can't be a common subsequence.

首页