• HDU5716 : 带可选字符的多字符串匹配


    shift-and算法,设$v[i][j]$表示文本串长度为$i$的前缀能否匹配模式串长度为$j$的前缀,$f[i][j]$表示字符$i$能否匹配模式串的第$j$个位置,那么有$v[i+1][j+1]=v[i][j] and f[s[i+1]][j+1]$。

    显然$j$这一维可以用bitset加速,时间复杂度$O(frac{nm}{64})$。

    #include<cstdio>
    #include<bitset>
    int n,i,j,flag;std::bitset<505>v,f[62];char s[2000010],t[99];
    inline int id(char x){
      if(x>='a'&&x<='z')return x-'a';
      if(x>='A'&&x<='Z')return x-'A'+26;
      if(x>='0'&&x<='9')return x-'0'+52;
      return -1;
    }
    int main(){
      while(gets(s)){
        scanf("%d",&n);
        for(flag=0,i=0;i<62;i++)f[i].reset();v.reset();
        for(i=1;i<=n;i++){
          scanf("%d%s",&j,t);
          for(j=0;t[j];j++)f[id(t[j])][i]=1;
        }
        v[0]=1;
        for(i=0;s[i];i++){
          if(id(s[i])<0)v.reset();else v=v<<1&f[id(s[i])];
          v[0]=1;
          if(v[n]==1)flag=1,printf("%d
    ",i-n+2);
        }
        if(!flag)puts("NULL");
        getchar();
      }
      return 0;
    }
  • 相关阅读:
    一条痛并快乐的路
    Daily Scrum 11.1
    Daily Scrum 10.31
    Daily Scrum 10.30
    Daily Scrum 10.29
    Daily Scrum 10.28
    Daily Scrum 10.27
    (Alpha)Let's-Chronos分数分配规则
    Daily Scrum 10.26
    Daily Scrum 10.25
  • 原文地址:https://www.cnblogs.com/clrs97/p/5985648.html
Copyright © 2020-2023  润新知