#P3881. [JLOI2008] CODES

    ID: 2818 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>字符串动态规划,dp搜索2008各省省选吉林

[JLOI2008] CODES

Description

Given nn 01\texttt{01} code strings S1,S2,,SnS_1, S_2, \dots, S_n, your task is to find a code string TT such that it can be decomposed in at least two different ways as a concatenation of the SiS_i.

For example:

Given 55 01\texttt{01} code strings: $S_1=\texttt{0110}, S_2=\texttt{00}, S_3=\texttt{111}, S_4=\texttt{001100}, S_5=\texttt{110}$. Then one valid code string TT is: \texttt{001100110}, which has the following two decompositions:

\texttt{00}+\texttt{110}+\texttt{0110} (S2+S5+S1)(S_2+S_5+S_1) or \texttt{001100}+\texttt{110} (S4+S5)(S_4+S_5).

But 0110110 does not meet the requirement; it has only one decomposition \texttt{0110}+\texttt{110} (S1+S5)(S_1+S_5).

You must find the shortest valid code string TT. If there are multiple shortest valid code strings TT, output the lexicographically smallest one.

Input Format

The first line contains an integer nn, the number of 01\texttt{01} code strings. Each of the next nn lines contains one 01\texttt{01} code string of length at most 2020.

Output Format

Output two lines. The first line is the length of the required code string TT. The second line is the code string TT. For all the testdata, a solution always exists.

5
0110
00
111
001100
110

9
001100110

Hint

  • n20n \le 20.

Translated by ChatGPT 5