当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3576:Language Recognition

Special Judge 特殊评判
题目描述

Deterministic Final-State Automaton (DFA) is a directed multigraph whose vertices are called states and edges are called transitions. Each DFA transition is labeled with a single letter. Moreover, for each state s and each letter l there is at most one transition that leaves s and is labeled with l. DFA has a single starting state and a subset of final states. DFA defines a language of all words that can be constructed by writing down the letters on a path from the starting state to some final state.

Given a language with a finite set of words it is always possible to construct a DFA that defines this language. The picture on the left shows such DFA for the language consisting of three words: fix, foo, ox. However, this DFA has 7 states, which is not optimal. The DFA on the right defines the same language with just 5 states.

Your task is to find the minimum number of states in a DFA that defines the given language.

输入解释

The first line of the input file contains a single integer number n (1 ≤ n5 000) — the number of words in the language. It is followed by n lines with a word on each line. Each word consists of 1 to 30 lowercase Latin letters from “a” to “z”. All words in the input file are different.

输出解释

Write to the output file a single integer number — the minimal number of states in a DFA that defines the language from the input file.

输入样例
#13
fix
foo
ox
#24
a
ab
ac
ad
输出样例
#15
#23

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3576

最后修改于 2020-10-29T07:05:05+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536