题目: 传送门 题意: 给你一个 n * m 的文本串 T, 再给你一个 r * c 的模式串 S: 问模式串 S 在文本串 T 中出现了多少次. 解: 法一: AC自动机 (正解) 670ms 把模式串的每一行当成一个字符串, 建一个AC自动机. 然后设cnt[ x ][ y ] 表示文本串中,以 (x, y) 这个点为矩阵右上角的点,且矩阵大小为 r * c的矩阵与模式串匹配了多少行. 那最终统计答案的时候, 只需要 o(n * m) 枚举所有点,记录那些 cnt[ x ][ y ] ==…
UVA - 10895 Matrix Transpose Time Limit:3000MS Memory Limit:Unknown 64bit IO Format:%lld & %llu [Submit] [Go Back] [Status] Description A: Matrix Transpose A matrix is a rectangular array of elements, most commonly numbers. A matrix with rows…
Code: #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<queue> using namespace std; const int maxn=103; const int maxd=1005; const int maxc=maxd*10; const int sigma=28; char A[maxd][maxd],B[maxn…
Description 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 line contains two integers N and M (N, M…
442 Matrix Chain MultiplicationSuppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multiplications are performed is arbitrary.However, the number of…
只看题目的话~~怎么也看不出来是网络流的题目的说啊~~~~ 建图好神奇~~ 最开始不懂---后来看了一下这篇-- http://www.cnblogs.com/AOQNRMGYXLMV/p/4280727.html 建立源点 st = 0,汇点 ed = r+c 因为正整数的范围是1到20,而流量可以是0,所以先将矩阵里面的每个数减去1,到最后输出答案的时候再加上1 把每一行看做一个节点 x,编号为1到r 把每一列看做一个节点y,编号为r+1到r+c st到x连边,容量为 Ai '- c y到e…