← 返回 meta 的题目列表Max Total Characters by Selecting Words with Unique Letters
类型:online_judge
Problem
Given an array of strings words, choose a subset and concatenate them in any order.
Constraint:
Across the entire concatenated string, no letter may appear more than once (letters cannot repeat across chosen words).
Return the maximum possible total length of such a concatenation.
Input
First line: integer k
Next k lines: one word per line
Output
An integer: the maximum length.
Typical Constraints
1 <= k <= 16 (larger needs bitmasking/pruning)
words contain only lowercase a-z
Example
Input:
4
un
iq
ue
aa
Output:
4
Explanation: pick un + iq => length 4; aa is invalid due to repeated letters within the word.
Example
Input
4
un
iq
ue
aa
Output
4