UVA - 11019(AC自动机)

Given an N × M matrix, your task is to find the number of occurences of an X × Y pattern.InputThe first line contains a single integer t (t ≤ 15), the number of test cases.For each case, the first ...
摘要由CSDN通过智能技术生成

Given an N × M matrix, your task is to find the number of occurences of an X × Y pattern.
Input
The first line contains a single integer t (t ≤ 15), the number of test cases.
For each case, the first line contains two integers N and M (N, M ≤ 1000). The next N lines
contain M characters each.
The next line contains two integers X and Y (X, Y ≤ 100). The next X lines contain Y characters
each.
Output
For each case, output a single integer in its own line, the number of occurrences.
Sample Input

2
1 1
x
1 1
y
3 3
abc
bcd
cde
2 2
bc
cd

Sample Output

0
2

题目大意:给出两个矩阵,问第二个矩阵在第一个矩阵中的出现次数。

解题思路:先将第二个矩阵的每一行加入AC自动机,然后让第一个矩阵中的每一行和第二个矩阵中的第几行匹配,然后用一个二维数组存以第一个矩阵的这一个点开始的矩阵与第二个矩阵匹配的字符串的数量。如果数量达到x,那么表示矩阵匹配。

代码:

#pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <queue>
//#include <random>
#include <time.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ls root<<1
#define rs root<<1|1
const int inf=1ll*1<<60;
const int maxn=1e4+10;
const int maxm=1e6+10;
int to[maxn][27],cnt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值