#P9960. [USACO19JAN] Guess the Animal B
[USACO19JAN] Guess the Animal B
Problem Description
Cow Bessie and her friend Elsie are tired of their nutshell game, so they want to play another common game called "Guess the Animal".
At the start of the game, Bessie thinks of an animal (most of the time she thinks of a cow, which makes the game quite boring, but once in a while Bessie can be more creative and think of something else). Then Elsie tries to guess the animal Bessie chose by asking some questions. Each question asks whether the animal has a certain feature, and Bessie answers "yes" or "no" to each question. For example:
Elsie: "Can this animal fly?"
Bessie: "No."
Elsie: "Does this animal eat grass?"
Bessie: "Yes."
Elsie: "Can this animal produce milk?"
Bessie: "Yes."
Elsie: "Does this animal moo?"
Bessie: "Yes."
Elsie: "Then I think this animal is a cow."
Bessie: "Correct!"
If we call the set of all animals that have all the features consistent with the questions Elsie has asked so far the "candidate set", then Elsie will keep asking questions until the candidate set contains only one animal, and then she will give that animal as her answer. For each question, Elsie will choose a feature of some animal to ask about (even if this feature does not help her further shrink the candidate set). She will not ask about the same feature twice.
Given all the animals Bessie and Elsie know and their features, find the maximum number of "yes" answers Elsie can receive before she correctly guesses the animal.
Input Format
The first line of input contains the number of animals (). The following lines each describe one animal. Each line starts with the animal's name, followed by an integer (), followed by the features of this animal. The animal names and features are strings of at most lowercase letters (a..z). No two animals have exactly the same set of features.
Output Format
Output the maximum number of "yes" answers Elsie can receive before the game ends.
4
bird 2 flies eatsworms
cow 4 eatsgrass isawesome makesmilk goesmoo
sheep 1 eatsgrass
goat 2 makesmilk eatsgrass
3
Hint
Sample Explanation 1
In this example, Elsie may receive "yes" answers in the dialogue (the example in the statement), and it is not possible to have a dialogue with more than "yes" answers.
Translated by ChatGPT 5