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. mysql 提权总结

    1.MOF提权 简单的说mof就是系统内部的一个程序,每隔一定时间系统就会以root权限去执行,我们将其替换然后执行我们的而已攻击代码.此举称之为mof提权. 以下便是脚本: #pragma name ...

  2. struct msghdr和struct cmsghdr【转载】

    理解struct msghdr当我第一次看到他时,他看上去似乎是一个需要创建的巨大的结构.但是不要怕.其结构定义如下:struct msghdr {    void         *msg_name ...

  3. sqlite3使用简介

    sqlite3使用简介 一.使用流程 要使用sqlite,需要从sqlite官网下载到三个文件,分别为sqlite3.lib,sqlite3.dll,sqlite3.h,然后再在自己的工程中配置好头文 ...

  4. 【并行计算】用MPI进行分布式内存编程(二)

    通过上一篇中,知道了基本的MPI编写并行程序,最后的例子中,让使用0号进程做全局的求和的所有工作,而其他的进程却都不工作,这种方式也许是某种特定情况下的方案,但明显不是最好的方案.举个例子,如果我们让 ...

  5. Android检测富文本中的<img标签并实现点击效果

    本文旨在:通过点击一张图片Toast输出位置与url链接. 闲话少说,实现原理大概是酱紫的::通过正则表达式检测富文本内的图片集合并获取url,在src=“xxx” 后面添加 onclick方法,至于 ...

  6. python-unittest学习

    在说unittest之前,先说几个概念: TestCase 也就是测试用例 TestSuite 多个测试用例集合在一起,就是TestSuite TestLoader是用来加载TestCase到Test ...

  7. ASP.NET Core 2.0 MVC 发布部署--------- Ubuntun 16.04 X64 具体操作

    .Net Core 部署到Ubuntu 16.04 中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务 ...

  8. Effective C++笔记(三):资源管理

    参考:http://www.cnblogs.com/ronny/p/3745098.html 资源:动态分配的内存.文件描述器.互斥锁.图形界面中的字型与笔刷.数据库连接以及网络sockets等,   ...

  9. Dagger:快速的依赖注入for 安卓&Java

    Dagger:快速的依赖注入for 安卓&Java 2014年5月8日 星期四 15:29 官网: http://square.github.io/dagger/ GitHub: https: ...

  10. mysql一个字符问题

    顺便记录一下在使用mysql过程中碰到的一些问题: 有时候使用脚本迁移数据时会碰到乱码的问题,即使将表字符集设置成utf8也无济于事,这个时候在执行sql之前加一句set names utf8即可.