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. 【Tomcat】tomcat设置http文件下载,配置文件下载目录

    tomcat作为http的下载服务器,网上有很多办法 但我认为最简单的是:(亲测有效) 1.直接把文件放在 /var/lib/tomcat6/webapps/ROOT 目录下, 2.然后在网址中访问: ...

  2. KKT条件和拉格朗日乘子法详解

    \(\frac{以梦为马}{晨凫追风}\) 最优化问题的最优性条件,最优化问题的解的必要条件和充分条件 无约束问题的解的必要条件 \(f(x)\)在\(x\)处的梯度向量是0 有约束问题的最优性条件 ...

  3. S3C6410 SPI全双工读写流程分析(原创)【转】

    转自:http://blog.csdn.net/hustyangju/article/details/21165721 原创博文,知识共享!转载请注明出处:http://blog.csdn.net/h ...

  4. 64_p5

    php-nette-bootstrap-2.4.3-1.fc26.noarch.rpm 20-Feb-2017 07:19 16290 php-nette-caching-2.5.3-1.fc26.n ...

  5. springMVC中ajax的实现

    function addDebtResult(){ var repayIds=$("#repayIds").val(); var lateFeeDay=$("#repay ...

  6. NuGet Package Explorer上传时报:failed to process request:'Method Not Allowed'错误解决办法

    相关日志:PUT /api/v2/package - 1000 -  NuGet+Package+Explorer/3.15.0.0+(Microsoft+Windows+NT+6.2.9200.0) ...

  7. Photon3Unity3D.dll 解析二——EventData

    EventData 包含Photon事件的所有内容 Code           用于表示事件,相当于主键ID,LiteEventCode定义了一部分服务端普遍事件事件: Parameters   事 ...

  8. Windows下 Tensorflow安装问题: Could not find a version that satisfies the requirement tensorflow

    Tensorflow 需要 Python 3.5/3.6  64bit 版本: 具体的安装方式可查看:https://www.tensorflow.org/install/install_window ...

  9. vuejs学习——vue+vuex+vue-router项目搭建(一)

    前言 快年底了却有新公司邀请了我,所以打算把上家公司的学到一下技术做一些总结和分享. 现在vuejs都2.0了,我相信也有很多朋友和我一样实际项目还是选择vue1.0的或者给新手一些参考,不管在选择哪 ...

  10. LR 报错误: C interpreter run time error: Error -- Unresolved symbol : vuser_end解决方法

    Action.c(33): Error: C interpreter run time error: Action.c (33):  Error -- Unresolved symbol : vuse ...