• 最长回文串 O(n)复杂度(manacher算法)


    manacher算法:点击打开链接

    邝斌模板:

    void Manacher(int len){
        int l = 0;
        s[l++] = 1;
        s[l++] = 2;
        for(int i = 0;i < len;i ++){
            s[l++] = line[i];
            s[l++] = 2;
        }
    
        int id = 0, mx = 0;
        for(int i = 1;i < l;i ++){
            Mp[i] = mx > i ? min(Mp[2*id-i],mx-i) : 1;
            while(s[i + Mp[i]] == s[i - Mp[i]])   Mp[i]++;
            if(i + Mp[i] > mx){
                mx = i+Mp[i];
                id = i;
            }
        }
    }



  • 相关阅读:
    java
    java
    java
    java
    java
    java
    java
    java
    sed命令的用法
    linux系统产生随机数的6种方法
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6351961.html
Copyright © 2020-2023  润新知