题目链接

C. Spy Syndrome 2
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.

For a given sentence, the cipher is processed as:

  1. Convert all letters of the sentence to lowercase.
  2. Reverse each of the words of the sentence individually.
  3. Remove all the spaces in the sentence.

For example, when this cipher is applied to the sentence

Kira is childish and he hates losing

the resulting string is

ariksihsidlihcdnaehsetahgnisol

Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of nlowercase English letters — the ciphered text t.

The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.

Output

Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.

Examples
input
30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note
output
Kira is childish and he hates losing 
input
12
iherehtolleh
5
HI
Ho
there
HeLLo
hello
output
HI there HeLLo 

把每一个小的串hash一下, 然后就可以在大的串里面找了, 具体看代码, 很清楚。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
map <ll, string> mp;
ll dp[];
void print(int n) {
if(!n)
return ;
string tmp = mp[dp[n]];
print(n-tmp.size());
cout<<tmp<<" ";
}
int main()
{
int n, m;
string s, str;
cin>>n>>s>>m;
for(int i = ; i<m; i++) {
cin>>str;
int len = str.size();
ll tmp = ;
for(int j = ; j<len; j++) {
tmp = tmp*+tolower(str[j]);
}
mp[tmp] = str;
}
mem1(dp);
dp[] = ;
int len = s.size();
for(int i = ; i<len; i++) {
ll tmp = ;
for(int j = i; j>=; j--) {
tmp = tmp*+s[j];
if(dp[j]!=- && mp.count(tmp)) {
dp[i+] = tmp;
break;
}
}
}
int i = ;
print(len);
return ;
}

codeforces 633C. Spy Syndrome 2 hash的更多相关文章

  1. Codeforces 633C Spy Syndrome 2 | Trie树裸题

    Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...

  2. Codeforces 633C Spy Syndrome 2(DP + Trie树)

    题目大概说给一个加密的字符串,加密规则是把原文转化成小写字母,然后各个单词反转,最后去掉空格.现在给几个已知的单词,还原加密的字符串. 和UVa1401一个道理.. 用dp[i]表示加密字符前i个字符 ...

  3. Codeforces 633C Spy Syndrome 2 【Trie树】+【DFS】

    <题目链接> 题目大意:给定一个只有小写字母组成的目标串和m个模式串(里面可能有大写字母),记目标串反过来后的串为S,让你从m个模式串中选出若干个组成S串(不区分大小写).输出任意一种方案 ...

  4. [codeforces] 633C Spy Syndrome 2

    原题 Trie树+dp 首先,我们可以简单的想到一种dp方式,就是如果这一段可以匹配并且可以与前一段接上,那么更新dp[i]为当前字符串的编号,然后倒推就可以得到答案. 但是,显然我们不能O(m)比较 ...

  5. CF#633C Spy Syndrome 2 DP+二分+hash

    Spy Syndrome 2 题意 现在对某个英文句子,进行加密: 把所有的字母变成小写字母 把所有的单词反过来 去掉单词之间的空格 比如:Kira is childish and he hates ...

  6. Codeforce 633C. Spy Syndrome 2

    C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Manthan, Codefest 16 C. Spy Syndrome 2 字典树 + dp

    C. Spy Syndrome 2 题目连接: http://www.codeforces.com/contest/633/problem/C Description After observing ...

  8. Manthan, Codefest 16 -C. Spy Syndrome 2

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. Codeforce 633.C Spy Syndrome 2

    C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 关于vs启动调试报错:CS0016: 未能写入输出文件“xxxxxxxx”--“目录名称无效。”解决方法

    很多人都会遇到这个错误,网友说一般这错误都是由于权限引起,我尝试按照博客写的方法,解决失败!http://www.cnblogs.com/finesite/archive/2011/01/28/194 ...

  2. OC语法9——Category类别

    Category(分类): 当我们在开发过程中要给类添加新的方法时,一般不要去动原类. 再不改动原类的限制下,怎么拓展类的方法?以往我们的做法是新建子类使其继承该类,然后通过子类拓展类的行为. OC提 ...

  3. mysql触发器使用注意

    1.在创建触发器的时候,语句中避免在一个select语句查询多个列,例如使用select a,b from table,应该分开使用select语句, 例如select a from table  s ...

  4. jQuery报错:

    jQuery报错:Uncaught ReferenceError: $ is not defined 在使用jQuery的时候,发现有如下报错: Uncaught ReferenceError: $ ...

  5. python执行shell命令

    1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如下命令,返回运行状态status os.system('cat /etc/passwdqc ...

  6. WIX 学习笔记- 1 简介

    一个项目 Code Complete 后,程序员们欢欣鼓舞,以为事情到此结束,可以 Happy 了.其实 Code Complete 五十之于百里.一个没有运行在设备上,为人们创造价值的项目是注定失败 ...

  7. qtcreator增加doxygen注释

    1,在以下网址找到和你的qt creator版本相对应的插件文件,还要注意系统版本 http://dev.kofee.org/projects/qtcreator-doxygen/files 2,根据 ...

  8. openstack 采用conductor的原因

    供参考. Tan0同学给我的解释: 两个原因 一个是为了isolation做准备 因为升级主要就是升DB的schema 如果让compute直接读写DB,那每次升级都得升compute 现在隔离开之后 ...

  9. sublime text 插件开发

    前言:术语和参考资料 sublime text 2的扩展模式相当的丰富.有多种方法可以修改语法高亮模式以及所有的菜单等.它还可以创建一个新的build系统,自动补全,语言定义,代码片段,宏定义,快捷键 ...

  10. 利用KVO监视一个view的frame

    首先,keyPath一定是frame,而不是frame.origin.x之类的路径,因为再点下去的话,就是访问结构体内部的值了,KVO是无法检测的,会报错找不到KeyPath. 代码如下: [_fun ...