← 返回 meta 的题目列表Select a Subset of Words to Maximize Unique Characters (No Duplicates)
类型:online_judge
AI/Coding: Choose a Subset of Words to Maximize Unique Characters (No Duplicates)
Given a list of words words (lowercase a-z), choose a subset and concatenate them in any order such that:
Each character appears at most once in the concatenated string (i.e., chosen words have disjoint character sets, and each chosen word itself contains no repeated characters).
Subject to the constraint above, maximize the total length of the concatenated string.
Output the maximum achievable length.
Input
First line: integer n
Next n lines: one word per line
Output
One integer: the maximum length
Constraints (as implied by the shared experience)
1 <= n <= 10000
Word length 1..26
Example
Input:
4
un
iq
ue
a
Output:
5
Example
Input
4
un
iq
ue
a
Output
5