Google Code Jam 2009 资格赛题目A

来源:互联网 发布:盛世启航网络 编辑:程序博客网 时间:2024/05/02 01:53

Problem
问题

After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words in this language.--这句的意思真难懂啊
在研究了几年之后,谷歌实验室的科学家们从一个遥远的星球上发现了一种外星语言。这种独特的外星语每一个词都由严格的L小写字母组成。同样,也有严格的D单词,在这种语言里。

Once the dictionary of all the words in the alien language was built, the next breakthrough was to discover that the aliens have been transmitting messages to Earth for the past decade. Unfortunately, these signals are weakened due to the distance between our two planets and some of the words may be misinterpreted. In order to help them decipher these messages, the scientists have asked you to devise an algorithm that will determine the number of possible interpretations for a given pattern.
一旦关于这个外星语的词典建立起来,接下来就是破译发来地球的消息了。不幸的是,这些信号经过长距离旅行之后非常脆弱,一些词可能错误了。为了帮助他们破译这些信息,科学家们请你设计一种算法,对于已经给出样式的外星语来确认可能的翻译的数量。

A pattern consists of exactly L tokens.
一种样式由严格的L符号组成。

Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded by parenthesis ( and ).
每一个符号既是一个符号小写字母(科学教非常确定这是字母)或者一组独特的小写字母被小括号括起来了。

For example: (ab)d(dc) means the first letter is either a or b, the second letter is definitely d and the last letter is either d or c.
比如:(ab)d(dc)意味着第一个字母是a或者b,第二个字母确定是d,最后一个字母是d或者c。

Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd, bdc.
因此,样式(ab)d(dc)看以表示成四种可能的形式。

Input
输入

The first line of input contains 3 integers, L, D and N separated by a space.
输入文件的第一行包含了三个整数L,D和N,由空格分隔。

D lines follow, each containing one word of length L.
接下来是,D行,每一行包含一个词,长度是L。

These are the words that are known to exist in the alien language.
这些词都是确认存在在外星语中的。

N test cases then follow, each on its own line and each consisting of a pattern as described above.
接下来是,N个测试案例,每一个词占一行,都由上面描述的样式组成。

You may assume that all known words provided are unique.
你可以假设所有被提供的词都是独一无二的。

Output
输出

For each test case, output
对于每一个测试案例,输出

Case #X: K

where X is the test case number, starting from 1, and K indicates how many words in the alien language match the pattern.
X是测试案例的数字,从1开始,K指明有多少词在外星语匹配样式里面。

Limits

限制
Small dataset

小数据集

1 ≤ L ≤ 10 词的长度不超过10
1 ≤ D ≤ 25 例子不超过20
1 ≤ N ≤ 10 测试案例不超过10

Large dataset

大数据集

1 ≤ L ≤ 15
1 ≤ D ≤ 5000
1 ≤ N ≤ 500

Sample

例子

Input

3 5 4
abc
bca
dac
dbc
cba
(ab)(bc)(ca)
abc
(abc)(abc)(abc)
(zyx)bc


Output

Case #1: 2
Case #2: 1
Case #3: 3
Case #4: 0

/*********************************************************************/

我已开始,没看明白怎么个意思.后看研究了例子才明白过来.
原来这个D是有特殊意义的,就像是密码学中的关键词,通过分析OUTPUT的结果,CASE相应的行后面对应的数字,其实是该行中包含的可能存在的D中的元素的个数.
举例说明,case #1:2。的意思是:(ab)(bc)(ca)存在的可能组合有:abc bca两种。
大家都知道理论上应该有2*2*2,共8种组合(abc,aba,acc,aca,bbc,bba,bcc,bca)。但是,这8种组合里面只有2个元素是出现在D的那5行里面的。所以~~,嘿嘿,终于明白问题了。
~~感慨,看明白英文题不容易啊。
在此,还得感谢马冬同志大半夜的陪我翻译~~,吼吼。

原创粉丝点击