Letter Balloons
InterviewTime limit1sMemory limit2048 MB
Given p problems and t school initials, find the largest number of schools that can each be the first solver of every problem spelled by their initials, with no overlap.
- Level
Medium4 of 10
- Topics
- Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
You are organizing a programming contest. The first team to solve each problem gets a balloon shaped like that problem's letter. For example, suppose there are twenty-three problems, labeled A through W. The members of Wossa Motta University want to be the first to solve problems M, U, and W, so they can fly their university's initials above their programming station. Many teams have the same idea and try to be the first solvers of the problems that spell their school's abbreviation. Both Wossa Motta U. and Spittinyer Institution might achieve this goal. Neither can do so if Muddinyer Institute solves problems M and I first. Muddinyer I. cannot achieve it if Wossa Motta U. or Spittinyer I. solves M or I first. Schools like Toe Tac Tech cannot succeed in any case, since a team can get at most one letter balloon for any problem. Xerxes College also cannot succeed, because this contest has no problem X. (We assume there is never a tie for the first solution to any problem.) What is the maximum number of teams that can display their school's initials with first-solver balloons at the end of the contest?
Input
The first line contains two integers and , where () is the number of problems and () is the number of teams. Problems are labeled with the first letters of the alphabet. Each of the following lines contains a nonempty string of at most 80 uppercase letters, the initials of a school. Each school has only one team, but several schools may have the same initials.
Output
Output a single integer: the maximum number of teams that can be the first solvers of all the problems that form the initials of their school name.