A14637 | Strange LCS
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given $n$ strings $s_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 $t$ is a subsequence of a string $s$ if $t$ can be obtained from $s$ by deletion of several (possibly, zero or all) symbols.
A string $t$ is a subsequence of a string $s$ if $t$ can be obtained from $s$ by deletion of several (possibly, zero or all) symbols.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \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 $n$ ( $2 \leq n \leq 10$ ) — the number of strings.
Each of the next $n$ lines contains the corresponding string $s_i$ . Each $s_i$ is non-empty, consists only of uppercase and lowercase English letters, and no character appears more than twice in each string.
The first line of each test case contains a single integer $n$ ( $2 \leq n \leq 10$ ) — the number of strings.
Each of the next $n$ lines contains the corresponding string $s_i$ . Each $s_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.
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 $2$ .
In the second test case, sets of characters of strings don't intersect, so any non-empty string can't be a common subsequence.
In the second test case, sets of characters of strings don't intersect, so any non-empty string can't be a common subsequence.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted