标签:algo main set memset pre str long mat code
==通配符匹配
数组开小R了2次。。
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL cf[1100]; char sa[1100],sb[1100]; int pos[1100],plen; LL ha[1100],hb[1100]; LL HASH(LL *h,int x,int y) { return h[y]-(h[x-1]*cf[y-x+1]); } bool f[1100][1100]; int main() { cf[1]=31;for(int i=2;i<=1000;i++)cf[i]=cf[i-1]*31; scanf("%s",sa+1);int alen=strlen(sa+1); sa[++alen]=‘?‘; ha[0]=0;plen=0; for(int i=1;i<=alen;i++) if(sa[i]>=‘A‘&&sa[i]<=‘Z‘) ha[i]=ha[i-1]*31LL+(LL(sa[i]-‘A‘+1)); else ha[i]=ha[i-1]*31LL+27LL, pos[++plen]=i; int n,ans=0; scanf("%d",&n); while(n--) { scanf("%s",sb+1);int blen=strlen(sb+1); sb[++blen]=‘?‘; hb[0]=0; for(int i=1;i<=blen;i++) hb[i]=hb[i-1]*31LL+(LL(sb[i]-‘A‘+1)); memset(f,false,sizeof(f));f[0][0]=true; for(int i=1;i<=plen;i++) { int pl=pos[i-1]+1,pr=pos[i]-1; int L=pr-pl+1; if(sa[pos[i]]==‘*‘) { for(int j=L+1;j<=blen;j++) { int l=(j-L+1)-1,r=j-1; if(f[i-1][l-1]==true) if(pos[i]==pos[i-1]+1||HASH(ha,pl,pr)==HASH(hb,l,r)) { for(int k=j-1;k<=blen;k++)f[i][k]=true; break; } } } else { for(int j=L+1;j<=blen;j++) { int l=(j-L+1)-1,r=j-1; if(f[i-1][l-1]==true) if(pos[i]==pos[i-1]+1||HASH(ha,pl,pr)==HASH(hb,l,r))f[i][j]=true; } } } if(f[plen][blen]==false)ans++; } printf("%d\n",ans); return 0; }
bzoj1966: [Ahoi2005]VIRUS 病毒检测
标签:algo main set memset pre str long mat code
原文地址:https://www.cnblogs.com/AKCqhzdy/p/8946865.html