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

建议使用的浏览器:

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

3599:Pumping Lemma

Special Judge 特殊评判
题目描述

In the theory of formal languages, the pumping lemma for regular languages bears importance for its characterization of an essential property of all regular languages.

In case of your unfamiliarity, we shall first review several related concepts. A regular language is the set of all strings accepted by a deterministic finite automaton (DFA). A DFA is an abstract model of computation informally explained below.

A DFA can be depicted by a state chart. Each node in the state chart represents a state. Of all states, exactly one is designated as the start state; and a subset of them is designated as a set of final states. Each labeled directed arc in the state chart represents a state transition. When the DFA works, it starts in the start state, reads symbols from a string one by one, and performs state transition accordingly. A state transition “xcy” means that if the DFA reads a symbol c when it is in state x, it will transit to state y. The DFA is said to accept a string if it is in a final state when it finishes reading symbols from the string.

Figure 5: Transition function δ of DFA M

Consider the state chart in Figure 5, which describes a DFA M. The states of M are {0, 1, 2, 3}. We designate 1 as the start state and 3 as the only final state. When fed with the string aba, M starts in state 1 and performs the state transitions “1 —a→ 2 —b→ 2 —a→ 3” to reach the final state 3. Consequently, M accepts the string aba. Precisely speaking, M accepts the regular language L = {abia : i ≥ 0} = {aa, aba, abba, …}.

The pumping lemma for regular languages, put informally, states that for any sufficiently long string w of a regular language L can be written, subject to some length constraints, as the concatenation of three substrings x, y and z such that the strings resulting from removing or repeating y in w, i.e. xz and xyyz, xyyyz, …, are also strings of L.

Given a DFA accepting a regular language L, find a string wL satisfying that w can be written as w = xyz so that {xz, xyz, xyyz, …} ⊆ L, and 0 < |y| ≤ |w| < 3n (| · | means the length of a string).

输入解释

The input contains a single test case describing a DFA whose states are {0, 1, 2, …, n} and which reads only lowercase letters. The first line contains n and the start state s (1 ≤ sn ≤ 1000). The second line contains an integer m (0 ≤ m ≤ 26n). Each of the following m lines contains an integer x, a symbol c and another integer y (1 ≤ xn; c ∈ Σ; 0 ≤ yn), specifying a state transition “xcy”. The state transition “xc→ 0” is implicitly assumed for any state x and symbol c if not otherwise specified. The next line contains an integer k (0 ≤ kn), which is followed by a line containing k integers, the final states of M. 0 is not a final state.

If there multiple choices of w, you may choose any one.

输出解释

If some w = xyzL satisfies the given requirements, print “x(y)z”; otherwise, print “*”.

输入样例
3 1
3
1 a 2
2 a 3
2 b 2
1
3
输出样例
a(b)a

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

源链接: POJ-3599

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

共提交 0

通过率 --%
时间上限 内存上限
1000 131072