bzoj3555(字串hash,疑問??)

2021-07-16 04:09:48 字數 552 閱讀 2156

自然溢位可以過,為什麼mod大質數就被卡??

這裡的自然溢位不用擔心,減去乙個數後出現負數的情況,減去之後就又轉成大整數了

#include#include#include#include#include#includeusing namespace std;

typedef long long ll;

const int n=30005;

const ll mod=1e+7;

const ll p=131;

char ch[n][209];

unsigned long long hs[n],a[n];

ll po[300];

int ans;

int n,len;

unsigned long long hash(int k)

int main()

int cnt;

for (int i=1;i<=len;i++) }

printf("%d",ans);

return 0;

}

字串(一) 字串Hash

今天開一手最不 tao 擅 yan 長的字串演算法 字串hash演算法。似乎提到字串的話,kmp應該是更為常見的一種,但是hash有它的優點,被犇們稱為 優雅的暴力 何謂hash?hash的中文稱為雜湊,這當然是音譯,直譯過來就是雜湊,或者也有叫預對映的。雜湊的作用就是通過某個特殊函式的對映,將任意...

KMP 字串 BZOJ4974字串大師

在kmp演算法中,fai lfail fail 指標有乙個特殊的性質,i f aili i fail i i fail i 是前i個字元的最小迴圈節大小。所以這題相當於就是說,給了你每個點的fail指標,求乙個滿足的字串。那麼按照建fail指標的方式倒過來做就好了 include include i...

BZOJ4974 字串大師

不難發現結論pe ri i nex ti,nex t 就是kmp裡的失配陣列。考慮構造乙個字串 s 滿足上述ne xt陣列,定義 i 的失配集為 n exti 1 1 的失配集。若ne xti 0 則si sne xti 若ne xti 0 則 i 必須和其失配集中的字元互不相同,因為字典序要最小,...