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

建议使用的浏览器:

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

1194:HIDDEN CODES

题目描述
A set of code words and a text are given. The text is supposed to contain a message made up of the code words embedded in the text in a peculiar (and possibly ambiguous) way.

The code words and the text are sequences made up of the upper and lower case letters of the English alphabet only. Case-sensitivity is assumed. The length of a code word is defined in the usual way: For example, the code word ALL has length 3.

The letters of a code word do not have to occur consecutively in the given text. For example, the code word ALL will always occur in the text within a subsequence in the form of AuLvL where u and v denote arbitrary (possibly empty) sequences of letters. We say that AuLvL is a covering sequence for ALL. In general, a covering sequence for a code word is defined as a subsequence of the text such that the first letter and the last letter of the subsequence are the same as those of the code word and it is possible to obtain the code word by deleting some (possibly none) of the letters of the subsequence. It should be noted that a code word may occur within one or more covering sequences or may not occur in the text at all, and that a covering sequence may be a covering sequence for more than one code word.

A covering sequence is identified by its start position (position of its first letter) and its end position (position of its last letter) in the text. (The first letter of the text is at position 1.) We say that two covering sequences, say c1 and c2, do not overlap if the start position of c1 is greater than (>) the end position of c2 or vice versa. Otherwise we say that the two covering sequences overlap.

To extract the message hidden in the text you undertake the task of forming a solution. A solution is a set of items, each consisting of a code word and a covering sequence for this code word, so that the following conditions are all satisfied:
a) the covering sequences do not overlap with each other;
b) a covering sequence does not exceed 1000 in length;
c) the sum of the lengths of the code words is maximal. (Each item contributes the length of the code word it contains to the sum.)

1 <= N <= 100 where N is the number of code words.
The maximum length of a code word is 100 letters.
1 <= length of the given text <= 1,000,000 letters.
We say that a covering sequence c for a code word w is right-minimal if no proper prefix of c (a proper prefix of c is an initial subsequence of c that is not equal to c) is a covering sequence for w. For example, for the code word ALL, AAALAL is a right-minimal covering sequence whereas AAALALAL is also a covering sequence, but not right-minimal.
It is guaranteed that in the given text
a) for each position in the text the number of right-minimal covering sequences containing that position does not exceed 2500;
b) the number of right-minimal covering sequences does not exceed 10,000.

输入解释
Your program is to read from standard input. The first line contains the value of N. Each of the following N input lines contains a code word which is a sequence of letters without any blank in between. Integers 1 through N serve as the id-numbers for the code words. The last line contains the text, which consists of a sequence of letters (terminated by an end-of-line character followed by the end-of-file symbol).

输出解释
Your program is to write to standard output. The first line will contain the sum obtained by your solution.
输入样例
4
RuN
RaBbit
HoBbit
StoP
StXRuYNvRuHoaBbvizXztNwRRuuNNP
输出样例
12

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

题目来源 IOI 1999

源链接: POJ-1194

最后修改于 2020-10-29T05:57:17+00:00 由爬虫自动更新

共提交 0

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