← 返回 meta 的题目列表Maximum Unique Characters Subset of Words
类型:online_judge
Given a list of words words (lowercase strings), select a subset (each word at most once) such that after concatenating the selected words:
No character appears more than once in the concatenated result.
Subject to that constraint, the number of distinct characters (equivalently, total length) is maximized.
Output any one optimal subset as a list of words.
Notes
If a word contains duplicate letters within itself, it can never be selected.
If multiple optimal subsets exist, return any.
Input
Line 1: integer n
Next n lines: one word per line
Output
The chosen words, one per line (any order). Print an empty line for empty set.
Constraints
Alphabet is a..z
Typical interview constraint: n <= 20 (enables backtracking/bitmask DP).
Example: Input:
4
jan
feb
mar
may
One valid optimal output:
jan
feb
Example
Input
4
jan
feb
mar
may
Output
jan
feb