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. python批量替换文件名

    替换关键字 #-*-coding:utf-8-*- import os import re filepath = u'E:\\CMMI4\\07_测试文档' files = os.walk(filep ...

  2. Codeforces Round #453 (Div. 1)

    Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出 ...

  3. eclipse 常见问题之字体更改、添加注释模板

    有些同学可能会和我有一样的困扰,每次想要更改字体大小.背景颜色等,都需要百度一下才知道怎么去做...不知道有没有这种情况的孩子,反正我经常遇到,老是记不住,今天写下来,顺带自己忘记的时候可以查看一下. ...

  4. SilverLight高亮显示文本

    文笔不好,就长话短说,就是想实现这样的效果,比如在成都二环路南一段一号附一号凤舞九天网吧 ,搜索 二环路 九天网吧 然后结果中高亮显示. <local:TextBlockHighLight Te ...

  5. beego学习笔记(4):开发文档阅读(5)

    controller的逻辑: 我们看下面的代码,就知道怎么传值的: import ( "github.com/astaxie/beego" ) type MainControlle ...

  6. gentoo emerge unable to sync

    gentoo emerge unable to sync Author: Tubo After setting SYNC to customized URL: SYNC="rsync://m ...

  7. Yii2使用驼峰命名的形式访问控制器

    yii2在使用的时候,访问控制器的时候,如果控制器的名称是驼峰命名法,那访问的url中要改成横线的形式.例如: public function actionRoomUpdate() { // }//访 ...

  8. day1作业一:编写登陆接口

    作业一:编写登陆接口 1.输入用户名和密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 Readme: (1)提示用户输入用户名: (2)用户名验证,验证是否已经锁定: (3)是否锁定:已锁定告诉 ...

  9. C# 6.0 新特性 (三)

    主构造函数 自动属性初始化表达式尤其适合与主构造函数结合使用.主构造函数为降低常见对象模式的繁琐程度提供了一种方法.此功能自五月以来已显著改进.更新包括: 主构造函数的可选实现主体:这将支持此前不受支 ...

  10. 【C#】编码史记

    计算机中的字是如何处理的? 如果你用放大镜看一下,可以看出屏幕上的字是由一个一个的像素点组成的,每一个字符用一组像素点拼接出来,这些像素点组成一幅图像,变成了我们的文字,计算机又是如何将我们的文字保存 ...