题目大意:给你一个矩阵T,问另一个矩阵P在这个矩阵T中出现过几次
可以用hash水,常数还小,双hash还卡不了
正解是把P每一行作为一个串,建一个AC自动机
用T的每一行去匹配,维护tot[i][j]表示T中左上角为i,j的T大小的矩阵,出现了T中的多少行
答案为tot[i][j] = x的i,j个数
各种卡常+反复提交,终于过了
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #define min(a, b) ((a) < (b) ? (a) : (b)) 7 #define max(a, b) ((a) > (b) ? (a) : (b)) 8 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) 9 inline void swap(int &a, int &b) 10 { 11 long long tmp = a;a = b;b = tmp; 12 } 13 inline void read(int &x) 14 { 15 x = 0;char ch = getchar(), c = ch; 16 while(ch < '0' || ch > '9') c = ch, ch = getchar(); 17 while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); 18 if(c == '-') x = -x; 19 } 20 21 const int INF = 0x3f3f3f3f; 22 const int MAXNODE = 10000 + 1; 23 const int MAXLEN = 1000 + 1; 24 25 int t,n,m,x,y,ans,cnt, tag[MAXNODE], ch[27][MAXNODE], tot[MAXLEN][MAXLEN], fail[MAXNODE], last[MAXNODE]; 26 char T[MAXLEN][MAXLEN], P[MAXLEN][MAXLEN]; 27 std::vector<int> node[MAXNODE]; 28 29 int bq[MAXNODE], btot; 30 void insert(int x) 31 { 32 int now = 0; 33 for(int i = 1;P[x][i] != '