QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100

#2401. 披萨派对!

Estadísticas

你正在协助组织一场计算机科学会议,并负责为会议嘉宾筹办披萨派对。每位嘉宾对披萨配料的组合都有自己的偏好,嘉宾们按桌子分组坐在会议中心的宴会厅里。每张桌子供应一个披萨。你需要通过寻找能让特定桌上的所有嘉宾都满意的披萨配料,来理清每张桌子的集体偏好。由于你是按配料付费的,会议组织者希望为每张桌子的披萨找到满足条件的最小配料集合。

披萨偏好以绝对形式或蕴含形式的陈述给出。关于 pepperoni(意大利辣香肠)的绝对偏好是指为了满足某位特定嘉宾,披萨上必须有 pepperoni 的陈述。蕴含偏好是一个条件语句。例如,偏好 if pepperoni and sausage then mushroom 表示如果披萨上有 pepperonisausage(香肠),那么也必须有 mushroom(蘑菇)。注意,蕴含偏好并未说明当 pepperonisausage 不在披萨上时,对 mushroom 的偏好。

嘉宾们已经按桌子分组,每张桌子的偏好也已汇总。你的任务是为每张桌子的披萨找到一种配料方案。

输入格式

输入的第一行包含一个整数 $c$ ($1 \le c \le 1\,000$),表示你试图制作的披萨的偏好数量。接下来是 $c$ 行,每行包含一个绝对偏好或蕴含偏好。

每种配料的名称是一个单词,长度不超过 10 个字符,仅由小写英文字母组成。单词 ifandorthen 不能作为披萨配料的名称。

绝对偏好由单个配料名称组成。所有蕴含偏好均为以下形式之一:if t1 and t2 and ... and tk then tk+1if t1 or t2 or ... or tk then tk+1,其中 $t_1, t_2, \dots, t_{k+1}$ 均为配料名称,且 $1 \le k \le 500$。

输出格式

对于给定的测试用例,输出一行,包含一个整数 $t$ —— 满足桌上所有嘉宾的披萨所需的最少配料数量。

样例

样例输入 1

4
peppers
if spinach and olives then tomatoes
spinach
feta

样例输出 1

3

样例输入 2

5
pepperoni
pineapple
if pepperoni and sausage then mushroom
ham
if pineapple and ham then bacon

样例输出 2

4

样例输入 3

4
pepperoni
sausage
if pepperoni and sausage then mushrooms
if mushrooms or peppers then cheese

样例输出 3

4

披萨派对场景

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.