Word Grouping
Time limit1sMemory limit1024 MB
Split N words into the fewest groups so that each group shares at least one common letter, with at most 15 distinct letters.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Adomas has decided to build a multidimensional crossword, and to do so he needs to split his words into groups.
He has chosen words. The words use only the first letters of the Latin alphabet. The same letter may appear several times within a word, and the words may have different lengths.
Adomas wants to split all of the words into as few groups as possible so that every group has at least one letter that is shared by all of the words in that group.
Determine the minimum number of groups into which the words can be split.
Input
The first line contains the number of words and the number of distinct letters used in the words. Each of the next lines contains one word — a string of at most 50 uppercase Latin letters that uses only the first letters of the alphabet.
Output
Output the minimum number of groups into which the words can be split.