zoukankan      html  css  js  c++  java
  • 后缀数组模板~~~

    int n,k;
    int sa[MaxN+10],rank[MaxN+10],tmp[MaxN+10],height[MaxN+10];
    bool compare_sa(int i,int j){
    	 if(rank[i] != rank[j] )return rank[i] < rank[j];
    	 else{
      	 	 int ri = i + k <= n ? rank[i+k] : -1; 
      	 	 int rj = j + k <= n ? rank[j+k] : -1;
    		 return ri < rj;	 
         }	 
    }
    void construct_sa(char *s,int *sa){
    	 n = strlen(s);
    	 repf(i,0,n){sa[i]=i;rank[i]=i<n?s[i]:-1;}
    	 for(k=1;k<=n;k*=2){
    		sort(sa,sa+n+1,compare_sa);
    		
    		tmp[sa[0]] = 0;
    		repf(i,1,n) tmp[sa[i]]=tmp[sa[i-1]] + (compare_sa(sa[i-1],sa[i])?1:0);
    		repf(i,0,n) rank[i]=tmp[i];
    	 }
    }
    void construct_lcp(char *s,int *sa,int *lcp){
    	  n=strlen(s);
    	 repd(i,n)rank[sa[i]] = i;
    	 int h=0;
    	 lcp[0]=0;
    	 rep(i,n){
      	    int  j =sa[rank[i] -1];
      	    
      	    if(h>0) h--;
      	    for(;j+h<n&&i+h<n;h++) if(s[j+h]!=s[i+h])break;
      	    
      	    lcp[rank[i]-1] = h;
      	 }
    }
    

      模板题目 : POJ 2774 与2217~~~拼接两个字符串,求出lcp~~分别属于两个字符串的sa[i] 与sa[i+1]的最大height为最长公共子串~~~

  • 相关阅读:
    ASP.NET MVC 动态加载图像
    ASP.NET:以域用户身份访问网络资源
    ASP.NET MVC 动态加载 *.ascx
    4月
    3月
    2月
    每天充点小能量
    每天进步一点点
    FreeMarker标签与使用
    eclipse启动tomcat, http://localhost:8080无法访问
  • 原文地址:https://www.cnblogs.com/UnkelTao/p/3361132.html
Copyright © 2011-2022 走看看