Uva 11019 Matrix Matcher(二维字符串匹配)

题意:给出一个n*m的字符矩阵T,你的任务是找出给定的x*y的字符矩阵P在T中出现了多少次.


分析:白书原题,先把P构造成一个AC自动机,然后在T中逐行匹配。用一个数组记录以一个点为左上角能匹配到P的多少行。


#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MAXNODE 10005
using namespace std;
int T,n,m,x,y;
char s[105][105],t[1005][1005];
struct Acautomata
{
	int ch[MAXNODE][26];
	int f[MAXNODE];
	vector<int> val[MAXNODE];
	int got[1005][1005];
	int tot;
	void init()
	{
		tot = 1;
		memset(ch[0],0,sizeof(ch[0]));
		memset(got,0,sizeof(got));
	}
	int idx(char c)
	{
		return c - 'a';
	}
	void insert(char *s,int v)
	{
		int u = 0,n = strlen(s);
		for(int i = 0;i < n;i++)
		{
			int c = idx(s[i]);
			if(!ch[u][c])
			{
				memset(ch[tot],0,sizeof(ch[tot]));
				val[tot].clear();
				ch[u][c] = tot++;
			}
			u = ch[u][c];
		}
		val[u].push_back(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值