Dominating Patterns
每次看着别人的代码改成自己的模板都很头大。。。空间少了个0卡了好久
裸题,用比map + string更高效的vector代替蓝书中的处理方法
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <cmath> 9 #define min(a, b) ((a) < (b) ? (a) : (b)) 10 #define max(a, b) ((a) > (b) ? (a) : (b)) 11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) 12 inline void swap(int &a, int &b) 13 { 14 long long tmp = a;a = b;b = tmp; 15 } 16 inline void read(int &x) 17 { 18 x = 0;char ch = getchar(), c = ch; 19 while(ch < '0' || ch > '9') c = ch, ch = getchar(); 20 while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); 21 if(c == '-') x = -x; 22 } 23 24 const int INF = 0x3f3f3f3f; 25 const int MAXNODE = 150 * 70 * 10; 26 27 int ch[MAXNODE][30], last[MAXNODE], root = 0, tag[MAXNODE], fail[MAXNODE], cnt, tot[MAXNODE]; 28 std::vector<int> node[MAXNODE]; 29 char s[1600][800]; 30 31 void insert(int x) 32 { 33 int now = root; 34 for(int i = 1;s[x][i] != '