您当前的位置: 首页 > 

*DDL_GzmBlog

暂无认证

  • 2浏览

    0关注

    605博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[luogu] CF7D Palindrome Degree 字符串hash+dp

*DDL_GzmBlog 发布时间:2021-10-02 13:00:01 ,浏览量:2

前言

怎么字符串hash 这么难啊(一堆hash公式)QAQ

代码借鉴 : https://www.luogu.com.cn/blog/yhttcr/solution-cf7d

传送门 : https://www.luogu.com.cn/problem/CF7D

思路

题目很简单明了 操作无非就两步

  • 判断子串是否回文
  • dp处理所有前缀之和

第二步按题意来非常简单

但是第一步,字符串hash没看懂

从 https://oi-wiki.org/string/hash/#_4入的hash 到https://zhuanlan.zhihu.com/p/79887898开始懂了一点

虽然每个博客/wiki 用的hash方法都不一样

回文字符串只需要 倒着处理 就行

也就是 我们正向的做一遍 类似进制转换的hash操作

然后 我们同时反向做一遍 进制转换的操作即可

(嗯 不理解就死记硬背吧)

还有一开始 我取233作为b竟然 hash碰撞了也是服了

同时我对1e9+7做M 也hash碰撞了 QAQ

CODE
#include 
using namespace std;
const int N = 5e6+10;
const int M = 1e9+7;
const int B =233;
int n,f[N],ans,fac = 1,fro,bac;
void solve()
{
    string s;
    cin>>s;
    int len = s.size();

    ///看成进制不就行了
    for(int i = 0 ; i>1]+1):0;
        
         if(fro == bac)
           ans+=(f[i]=f[i-1 >>1]+1);
    }
    cout            
关注
打赏
1657615554
查看更多评论
0.0368s