https://code.google.com/codejam/contest/90101/dashboard#s=p0

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.

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. 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. Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd, bdc.

Input

The first line of input contains 3 integers, LD and N separated by a space. D lines follow, each containing one word of length 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. 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.

Limits

Small dataset

1 ≤ L ≤ 10
1 ≤ D ≤ 25
1 ≤ N ≤ 10

Large dataset

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

Sample

Input 
 
Output 
 
3 5 4
abc
bca
dac
dbc
cba
(ab)(bc)(ca)
abc
(abc)(abc)(abc)
(zyx)bc
Case #1: 2
Case #2: 1
Case #3: 3
Case #4: 0

Solution:

int solve(int L, int D, vector<string>dictionary, string pattern)
{ int matches = ; for (int di = ; di < dictionary.size(); di++) {
string dw = dictionary.at(di); bool bracket = false;
bool inbracket_match = false;
bool word_match = true;
int cci = ;
for (int i = ; i < pattern.length(); i++) {
char chr = pattern[i];
if (chr == '(') {
bracket = true;
} else if (chr == ')') {
bracket = false;
if (!inbracket_match) {
word_match = false;
break;
}
inbracket_match = false;
cci++;
} else {
if (bracket) {
if (dw[cci] == chr) {
inbracket_match = true;
}
} else {
if (dw[cci] != chr) {
word_match = false;
break;
}
cci++;
}
}
} if (word_match) {
matches++;
} } return matches; } int main() {
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout); int L, D;
scanf("%d\n", &L);
scanf("%d\n", &D); int CN;
scanf("%d\n", &CN);
if (!CN) {
cerr << "Check input!" << endl;
exit();
} vector<string> dict;
for (int di = ; di < D; di++) {
char *word = new char[L];
scanf("%s\n", word);
string strword = string(word, L);
dict.push_back(strword);
} for (int case_i = ; case_i <= CN; case_i++) {
string pattern;
cin >> pattern; auto result = solve(L, D, dict, pattern);
printf("Case #%d: %d\n", case_i, result);
} fclose(stdin);
fclose(stdout);
return ;
}

Google Code Jam 2009 Qualification Round Problem A. Alien Language的更多相关文章

  1. Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam

    本题的 Large dataset 本人尚未解决. https://code.google.com/codejam/contest/90101/dashboard#s=p2 Problem So yo ...

  2. Google Code Jam 2009 Qualification Round Problem B. Watersheds

    https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...

  3. [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  4. [C++]Standing Ovation——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  5. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha

    Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...

  6. Google Code Jam 2014 资格赛:Problem D. Deceitful War

    This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...

  7. [刷题]Google Code Jam 2017 - Round1 C Problem A. Ample Syrup

    https://code.google.com/codejam/contest/3274486/dashboard Problem The kitchen at the Infinite House ...

  8. Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

    Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...

  9. Google Code Jam 2014 资格赛:Problem C. Minesweeper Master

    Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...

随机推荐

  1. weblogic 开启注意问题

    1.关闭防火墙 service iptables stop chkconfig iptables off 2.weblogic unable to get file lock问题 我的解决办法是ps ...

  2. Shell-免键盘输入

    Code: #!/bin/sh command1="ssh-keygen -t rsa -f /root/.ssh/id_rsa" expect -c " spawn $ ...

  3. 安全测试===CSRF攻击简介

    http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html

  4. jplayer.js 与 video.js

    HTML5 - 两款基于JS的视频播放器 都是基于h5 video 标签,如果不支持则会自动转成flash,这里个人比较推荐使用jplayer; 1.video.js pc端有时候会与视频打交道,如果 ...

  5. python 多线程, 多进程, 协程

    1. 介绍: threading用于提供线程相关的操作,线程是应用程序中工作的最小单元.python当前版本的多线程库没有实现优先级.线程组,线程也不能被停止.暂停.恢复.中断. 2. 1  线程执行 ...

  6. MySQL----示例知识点整理

    示例语句: ),hour(c.created_at) from `behavior_client_view` c join `behavior_share` s on c.share_uuid=s.u ...

  7. vue框架muse-ui官网文档主题错误毕竟【01】

    在使用了element-ui后,总觉得不尽兴,再学一个响应式的muse-ui发现是个小众框架,但是我很喜欢. 指出官网文档里的主题使用描述错误. 首先,在vue-cli里安装raw-loader:np ...

  8. Windows 10家庭版远程桌面连接错误

    由于需要操作远程服务器,经常使用“远程桌面连接”工具,一直很正常.今天突然提示 出现身份验证错误,可能是由于 CredSSP加密Oracle修正.什么情况!! 根据提示的地址https://go.mi ...

  9. Docker下使用daocloud镜像加速(基于Centos6)

    Docker加速器使用时不需要任何额外操作.就像这样下载官方Ubuntu镜像 实际操作(添加镜像源):在 /etc/sysconfig/docker下添加两条命令 other_args="- ...

  10. Python数据类型-集合(set)

    1.创建集合 集合的创建不同于前两种数据结构. 集合通过set(iterable)方法创建,参数iterable为可迭代对象. 示例代码: s1 = set('好好学习天天想上') # 将字符串分解为 ...