5695138290(10)
i=0910i×digiti

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
A1,A2,...,An

S1=A1

S2=A1+A2

S3=A1+A2+A3

S4=A1+A2+A3+A4

S5=A1+A2+A3+A4+A5

Hash

  • 字串編碼!!
  • 這裡使用 Rabin-Karp rolling hash
  • 字串
    S
    長度
    n
  • 假設質數
    p=65537
    M=109+7
  • 記得都要取模
    i=0|S|1pi×S[i]

    i=0|S|1p|S|1i×S[i]
  • 前綴hash值:
    pre[i]=j=0ipijS[j]
  • 然後,
    pre[j]=pre[j1]p+S[j]
  • 某一段的hash:
    hash(i,j)=pre[j]pre[i1]pji+1

補:HASH碰撞機率

  • 生日問題~
  • 推導過程超出高中數學範圍,在此忽略
  • 碰撞機率概算公式:(
    N
    為字串數量,
    M
    為可能值得數量 空間 值域大小)
    1exp(N2/(2×M))

    1eN2/(2×M)

Trie

  • 就是字典樹~
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 圖片來源:https://github.com/Vercaca/Trie
  • 實做遇到困難可以相互討論一下喔~