No.1512 Composition
Problem Statement
For a string $t$, if the characters of $t$ are arranged in ascending order, we call $t$ a good string.
For example, aabc,axz, the empty string, and so on are good strings, but cba,aza, and so on are not good strings.
You are given $N$ strings consisting of lowercase English letters.
For each of the $N$ strings, choose whether to select it or not, and concatenate the selected strings in any order to form a good string $X$. Find the maximum possible length of $X$.
Input
$N$ $S_1$ $S_2$ $\vdots$ $S_N$
Output
Output the answer, followed by a newline.
Sample
Sample 1
Input
3 aa ab ba
Output
4
The maximum is achieved by $S_1+S_2=$aaab.
Sample 2
Input
3 cba db kji
Output
0
It may be impossible to form a good string of length $1$ or more.
Sample 3
Input
4 abc ab bbccdd de
Output
10
Strings such as abcde, abbbccddde are possible; among these, output the maximum length, $10$.
Sample 4
Input
3 ab cd f
Output
5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ぷら
nok0
だれ