DFS统计#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<vector> #include<set> #include<map> #include<string> #include<algorithm> #define FOR(i,a,b) for(i=(a);i<=(b);i++) #define ROF(i,a,b) for(i=(a);i>=(b);i--) #define N 100100 #define pb push_back using namespace std; typedef long long LL;
...
Read more »
Views:
309
|
Added by:
dhy0077
|
Date:
10.04.2013
|
C++:void KMP() { //Init int i,j,old_i; P[1]=0,j=0; FOR(i,2,m) { while ((j>0)&&(B[j+1]!=B[i])) j=P[j]; if (B[j+1]==B[i]) j++; P[i]=j; } //Doit j=0; FOR(i,1,n) { while ((j>0)&&(B[j+1]!=A[i])) j=P[j]; if (B[j+1]==A[i]) j++; if (j==m){ans++;j=P[j];} } }
Views:
347
|
Added by:
dhy0077
|
Date:
10.04.2013
| |