{"id":65808,"date":"2026-01-25T17:56:55","date_gmt":"2026-01-25T09:56:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/65808.html"},"modified":"2026-01-25T17:56:55","modified_gmt":"2026-01-25T09:56:55","slug":"kmp%e7%ae%97%e6%b3%95%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/65808.html","title":{"rendered":"KMP\u7b97\u6cd5\uff08\u4e00\uff09"},"content":{"rendered":"<h2 id=\"%E4%B8%80%E3%80%81%E7%AE%80%E5%8D%95%E6%A8%A1%E5%BC%8F%E5%8C%B9%E9%85%8D%E7%AE%97%E6%B3%95%EF%BC%88BF%20%E7%AE%97%E6%B3%95%EF%BC%89\">\u4e00\u3001\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;BF \u7b97\u6cd5&#xff09;<\/h2>\n<hr \/>\n<h3 id=\"1.%20%E4%BB%80%E4%B9%88%E6%98%AF%E7%AE%80%E5%8D%95%E6%A8%A1%E5%BC%8F%E5%8C%B9%E9%85%8D%E7%AE%97%E6%B3%95\">1. \u4ec0\u4e48\u662f\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5<\/h3>\n<p>\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff0c;\u53c8\u79f0\u6734\u7d20\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;Brute Force&#xff0c;\u7b80\u79f0 BF \u7b97\u6cd5&#xff09;&#xff0c;<br \/>\n\u662f\u5b57\u7b26\u4e32\u5339\u914d\u4e2d\u6700\u57fa\u672c\u3001\u6700\u76f4\u89c2\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u662f\u6307\u5728\u4e3b\u4e32\u4e2d\u627e\u5230\u4e0e\u6a21\u5f0f\u4e32(\u60f3\u8981\u641c\u7d22\u7684\u67d0\u4e2a\u5b57\u7b26\u4e32)\u76f8\u540c\u7684\u5b50\u4e32&#xff0c;\u5e76\u8fd4\u56de\u5176\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\u91c7\u7528\u5b9a\u957f\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784&#xff0c;\u7ed9\u51fa\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u4e32\u64cd\u4f5c\u7684\u66b4\u529b\u5339\u914d\u7b97\u6cd5\u3002<\/p>\n<p>\u95ee\u9898\u63cf\u8ff0&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e3b\u4e32 S \u548c\u4e00\u4e2a\u6a21\u5f0f\u4e32 P&#xff0c;<br \/>\n\u5224\u65ad P \u662f\u5426\u662f S \u7684\u5b50\u4e32&#xff0c;<br \/>\n\u82e5\u662f&#xff0c;\u8fd4\u56de\u7b2c\u4e00\u6b21\u5339\u914d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\/*<br \/>\n * \u51fd\u6570\u529f\u80fd&#xff1a;\u6734\u7d20\u6a21\u5f0f\u5339\u914d&#xff08;BF\u7b97\u6cd5&#xff09;<br \/>\n * \u5728\u4e3b\u4e32 S \u4e2d\u67e5\u627e\u6a21\u5f0f\u4e32 T \u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\n * \u8fd4\u56de\u503c&#xff1a;<br \/>\n *   \u82e5\u5339\u914d\u6210\u529f&#xff0c;\u8fd4\u56de\u5339\u914d\u8d77\u59cb\u4e0b\u6807&#xff08;\u4ece1\u5f00\u59cb&#xff09;<br \/>\n *   \u82e5\u5339\u914d\u5931\u8d25&#xff0c;\u8fd4\u56de 0<br \/>\n *\/<br \/>\nint Index(SString S, SString T) {<br \/>\n    int i &#061; 1;  \/\/ i \u6307\u5411\u4e3b\u4e32 S \u5f53\u524d\u6bd4\u8f83\u7684\u4f4d\u7f6e<br \/>\n    int j &#061; 1;  \/\/ j \u6307\u5411\u6a21\u5f0f\u4e32 T \u5f53\u524d\u6bd4\u8f83\u7684\u4f4d\u7f6e<\/p>\n<p>    \/\/ \u5f53\u4e3b\u4e32\u548c\u6a21\u5f0f\u4e32\u5747\u672a\u8d8a\u754c\u65f6\u7ee7\u7eed\u6bd4\u8f83<br \/>\n    while (i &lt;&#061; S.length &amp;&amp; j &lt;&#061; T.length) {<\/p>\n<p>        \/\/ \u5f53\u524d\u5b57\u7b26\u76f8\u7b49&#xff0c;\u7ee7\u7eed\u6bd4\u8f83\u540e\u7eed\u5b57\u7b26<br \/>\n        if (S.ch[i] &#061;&#061; T.ch[j]) {<br \/>\n            i&#043;&#043;;<br \/>\n            j&#043;&#043;;<br \/>\n        }<br \/>\n        \/\/ \u5f53\u524d\u5b57\u7b26\u4e0d\u76f8\u7b49&#xff0c;\u6a21\u5f0f\u4e32\u91cd\u65b0\u4ece\u5934\u5f00\u59cb\u5339\u914d<br \/>\n        else {<br \/>\n            \/\/ \u4e3b\u4e32\u6307\u9488\u56de\u9000\u5230\u672c\u6b21\u5339\u914d\u8d77\u59cb\u4f4d\u7f6e\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26<br \/>\n            i &#061; i &#8211; j &#043; 2;<br \/>\n            \/\/ \u6a21\u5f0f\u4e32\u6307\u9488\u56de\u5230\u8d77\u59cb\u4f4d\u7f6e<br \/>\n            j &#061; 1;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u82e5\u6a21\u5f0f\u4e32\u5df2\u5168\u90e8\u5339\u914d\u5b8c\u6210<br \/>\n    if (j &gt; T.length) {<br \/>\n        \/\/ \u8fd4\u56de\u5339\u914d\u6210\u529f\u7684\u8d77\u59cb\u4f4d\u7f6e<br \/>\n        return i &#8211; T.length;<br \/>\n    }<br \/>\n    \/\/ \u5339\u914d\u5931\u8d25<br \/>\n    else {<br \/>\n        return 0;<br \/>\n    }<br \/>\n}<\/p>\n<hr \/>\n<h3 id=\"2.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%80%9D%E6%83%B3\">2. BF \u7b97\u6cd5\u7684\u57fa\u672c\u601d\u60f3<\/h3>\n<p>\u6838\u5fc3\u601d\u60f3\u4e00\u53e5\u8bdd\u6982\u62ec&#xff1a;<\/p>\n<p>\u5c06\u6a21\u5f0f\u4e32\u4e0e\u4e3b\u4e32\u7684\u6bcf\u4e00\u4e2a\u53ef\u80fd\u8d77\u59cb\u4f4d\u7f6e\u8fdb\u884c\u9010\u5b57\u7b26\u6bd4\u8f83&#xff0c;<br \/>\n\u4e00\u65e6\u51fa\u73b0\u4e0d\u5339\u914d&#xff0c;<br \/>\n\u6a21\u5f0f\u4e32\u56de\u5230\u8d77\u59cb\u4f4d\u7f6e&#xff0c;<br \/>\n\u4e3b\u4e32\u4ece\u4e0b\u4e00\u4e2a\u5b57\u7b26\u91cd\u65b0\u5f00\u59cb\u6bd4\u8f83\u3002<\/p>\n<hr \/>\n<h3 id=\"3.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E6%8C%87%E9%92%88%E5%AE%9A%E4%B9%89\">3. BF \u7b97\u6cd5\u7684\u6307\u9488\u5b9a\u4e49<\/h3>\n<p>\u5728\u7b97\u6cd5\u6267\u884c\u8fc7\u7a0b\u4e2d&#xff0c;\u901a\u5e38\u8bbe\u7f6e\u4e24\u4e2a\u6307\u9488&#xff1a;<\/p>\n<ul>\n<li>\n<p>i&#xff1a;\u6307\u5411\u4e3b\u4e32 S \u4e2d\u5f53\u524d\u6b63\u5728\u6bd4\u8f83\u7684\u5b57\u7b26<\/p>\n<\/li>\n<li>\n<p>j&#xff1a;\u6307\u5411\u6a21\u5f0f\u4e32 P \u4e2d\u5f53\u524d\u6b63\u5728\u6bd4\u8f83\u7684\u5b57\u7b26<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"4.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E6%AF%94%E8%BE%83%E8%A7%84%E5%88%99\">4. BF \u7b97\u6cd5\u7684\u6bd4\u8f83\u89c4\u5219<\/h3>\n<li>\n<p>\u5b57\u7b26\u76f8\u7b49<\/p>\n<p>S[i] &#061;&#061; P[j]<\/p>\n<ul>\n<li>\n<p>i&#043;&#043;<\/p>\n<\/li>\n<li>\n<p>j&#043;&#043;<\/p>\n<\/li>\n<li>\n<p>\u7ee7\u7eed\u6bd4\u8f83\u4e0b\u4e00\u4e2a\u5b57\u7b26<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b57\u7b26\u4e0d\u76f8\u7b49&#xff08;\u5931\u914d&#xff09;<\/p>\n<p>S[i] !&#061; P[j]<\/p>\n<ul>\n<li>\n<p>\u4e3b\u4e32\u56de\u9000&#xff1a;i &#061; i &#8211; j &#043; 1<\/p>\n<\/li>\n<li>\n<p>\u6a21\u5f0f\u4e32\u56de\u5230\u8d77\u70b9&#xff1a;j &#061; 0<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h3 id=\"5.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E5%9B%BE%E8%A7%A3%E8%BF%87%E7%A8%8B%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89\" style=\"background-color:transparent\">5. BF \u7b97\u6cd5\u7684\u56fe\u89e3\u8fc7\u7a0b&#xff08;\u91cd\u70b9&#xff09;<\/h3>\n<h4 id=\"%E7%A4%BA%E4%BE%8B%E5%AD%97%E7%AC%A6%E4%B8%B2\">\u793a\u4f8b\u5b57\u7b26\u4e32<\/h4>\n<p>\u4e3b\u4e32 S&#xff1a; a b a b a a b c a<br \/>\n\u4e0b\u6807&#xff1a;   0 1 2 3 4 5 6 7 8<br \/>\n\u6a21\u5f0f P&#xff1a; a b a a b<br \/>\n\u4e0b\u6807&#xff1a;   0 1 2 3 4<\/p>\n<hr \/>\n<h4 id=\"%E7%AC%AC%E4%B8%80%E6%AC%A1%E5%8C%B9%E9%85%8D%E5%B0%9D%E8%AF%95\">\u7b2c\u4e00\u6b21\u5339\u914d\u5c1d\u8bd5<\/h4>\n<p>S: a b a b a a b c a<br \/>\nP: a b a a b<br \/>\n   \u2191 \u2191 \u2191<\/p>\n<ul>\n<li>\n<p>a &#061;&#061; a \u2713<\/p>\n<\/li>\n<li>\n<p>b &#061;&#061; b \u2713<\/p>\n<\/li>\n<li>\n<p>a &#061;&#061; a \u2713<\/p>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6\u6bd4\u8f83\u5230&#xff1a;<\/p>\n<p>S[3] &#061; b<br \/>\nP[3] &#061; a \u2192 \u5931\u914d<\/p>\n<hr \/>\n<h4 id=\"%E5%8F%91%E7%94%9F%E5%A4%B1%E9%85%8D%E5%90%8E%E7%9A%84%E5%A4%84%E7%90%86%EF%BC%88%E5%85%B3%E9%94%AE%EF%BC%89\">\u53d1\u751f\u5931\u914d\u540e\u7684\u5904\u7406&#xff08;\u5173\u952e&#xff09;<\/h4>\n<p>i &#061; i &#8211; j &#043; 1 &#061; 3 &#8211; 3 &#043; 1 &#061; 1<br \/>\nj &#061; 0<\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e3b\u4e32\u56de\u5230\u4e0b\u4e00\u4e2a\u53ef\u80fd\u8d77\u70b9<\/p>\n<\/li>\n<li>\n<p>\u6a21\u5f0f\u4e32\u91cd\u65b0\u4ece\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5f00\u59cb\u6bd4\u8f83<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4 id=\"%E7%AC%AC%E4%BA%8C%E6%AC%A1%E5%8C%B9%E9%85%8D%E5%B0%9D%E8%AF%95\">\u7b2c\u4e8c\u6b21\u5339\u914d\u5c1d\u8bd5<\/h4>\n<p>S: a b a b a a b c a<br \/>\n     a b a a b<\/p>\n<p>\u7ee7\u7eed\u9010\u5b57\u7b26\u6bd4\u8f83&#xff0c;\u4ecd\u4f1a\u5931\u8d25\u3002<\/p>\n<hr \/>\n<h4 id=\"%E4%B8%8D%E6%96%AD%E9%87%8D%E5%A4%8D%E4%B8%8A%E8%BF%B0%E8%BF%87%E7%A8%8B\">\u4e0d\u65ad\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b<\/h4>\n<p>\u76f4\u5230&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u627e\u5230\u5b8c\u5168\u5339\u914d<\/p>\n<\/li>\n<li>\n<p>\u6216\u4e3b\u4e32\u5269\u4f59\u957f\u5ea6\u4e0d\u8db3\u4ee5\u5339\u914d\u6a21\u5f0f\u4e32<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"6.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E7%89%B9%E7%82%B9%E6%80%BB%E7%BB%93\">6. BF \u7b97\u6cd5\u7684\u7279\u70b9\u603b\u7ed3<\/h3>\n<h4 id=\"%E4%BC%98%E7%82%B9\">\u4f18\u70b9<\/h4>\n<ul>\n<li>\n<p>\u601d\u60f3\u7b80\u5355<\/p>\n<\/li>\n<li>\n<p>\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"%E7%BC%BA%E7%82%B9\">\u7f3a\u70b9<\/h4>\n<ul>\n<li>\n<p>\u5b58\u5728\u5927\u91cf\u91cd\u590d\u6bd4\u8f83<\/p>\n<\/li>\n<li>\n<p>\u6548\u7387\u8f83\u4f4e<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"7.%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6\">7. \u65f6\u95f4\u590d\u6742\u5ea6<\/h3>\n<ul>\n<li>\n<p>\u6700\u574f\u60c5\u51b5\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a; O(n \u00d7 m)<\/p>\n<\/li>\n<li>\n<p>\u5f53\u4e3b\u4e32\u548c\u6a21\u5f0f\u4e32\u4e2d\u542b\u6709\u5927\u91cf\u91cd\u590d\u5b57\u7b26\u65f6&#xff0c;\u6027\u80fd\u6700\u5dee<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"8.%20BF%20%E7%AE%97%E6%B3%95%E7%9A%84%E6%9C%AC%E8%B4%A8%E9%97%AE%E9%A2%98\" style=\"background-color:transparent\">8. BF \u7b97\u6cd5\u7684\u672c\u8d28\u95ee\u9898<\/h3>\n<p>BF \u7b97\u6cd5\u5728\u5931\u914d\u65f6<br \/>\n\u5b8c\u5168\u6ca1\u6709\u5229\u7528\u5df2\u5339\u914d\u7684\u90e8\u5206\u4fe1\u606f&#xff0c;<br \/>\n\u5bfc\u81f4\u4e3b\u4e32\u548c\u6a21\u5f0f\u4e32\u9891\u7e41\u56de\u9000\u3001\u91cd\u590d\u6bd4\u8f83\u3002<\/p>\n<hr \/>\n<h2 id=\"%E4%BA%8C%E3%80%81KMP%20%E7%AE%97%E6%B3%95%EF%BC%88%E4%B8%8D%E6%B6%89%E5%8F%8A%20next%EF%BC%89\">\u4e8c\u3001KMP \u7b97\u6cd5&#xff08;\u4e0d\u6d89\u53ca next&#xff0c;\u4ec5\u7b97\u6cd5\u601d\u60f3&#xff09;<\/h2>\n<hr \/>\n<h3 id=\"1.%20%E4%BB%80%E4%B9%88%E6%98%AF%20KMP%20%E7%AE%97%E6%B3%95\">1. \u4ec0\u4e48\u662f KMP \u7b97\u6cd5<\/h3>\n<p>KMP \u7b97\u6cd5\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u5b57\u7b26\u4e32\u5339\u914d\u7b97\u6cd5&#xff0c;<br \/>\n\u7531 Knuth\u3001Morris\u3001Pratt \u4e09\u4f4d\u5b66\u8005\u63d0\u51fa\u3002<\/p>\n<p>\u63d0\u51fa\u76ee\u7684&#xff1a;<\/p>\n<p>\u5728\u4fdd\u8bc1\u6b63\u786e\u5339\u914d\u7684\u524d\u63d0\u4e0b&#xff0c;<br \/>\n\u51cf\u5c11\u65e0\u6548\u6bd4\u8f83&#xff0c;<br \/>\n\u63d0\u9ad8\u5b57\u7b26\u4e32\u5339\u914d\u6548\u7387\u3002<\/p>\n<hr \/>\n<h3 id=\"2.%20KMP%20%E7%AE%97%E6%B3%95%E7%9A%84%E6%A0%B8%E5%BF%83%E6%80%9D%E6%83%B3\">2. KMP \u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3<\/h3>\n<p>\u4e00\u53e5\u8bdd&#xff1a;<\/p>\n<p>\u5f53\u5339\u914d\u5931\u8d25\u65f6&#xff0c;<br \/>\n\u4e0d\u56de\u9000\u4e3b\u4e32\u6307\u9488&#xff0c;<br \/>\n\u800c\u662f\u5229\u7528\u6a21\u5f0f\u4e32\u81ea\u8eab\u7684\u7ed3\u6784\u4fe1\u606f&#xff0c;<br \/>\n\u5c06\u6a21\u5f0f\u4e32\u79fb\u52a8\u5230\u4e00\u4e2a\u201c\u5408\u7406\u7684\u4f4d\u7f6e\u201d\u3002<\/p>\n<p>\u8981\u4e86\u89e3\u6a21\u5f0f\u4e32\u7684\u7ed3\u6784&#xff0c;\u9996\u5148\u8981\u5f04\u6e05\u695a\u51e0\u4e2a\u6982\u5ff5:\u524d\u7f00\u3001\u540e\u7f00\u548c\u90e8\u5206\u5339\u914d\u503c\u3002\u524d\u7f00\u662f\u6307\u9664\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u5916&#xff0c;\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5934\u90e8\u5b50\u4e32;\u540e\u7f00\u662f\u6307\u9664\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5916&#xff0c;\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5c3e\u90e8\u5b50\u4e32;\u90e8\u5206\u5339\u914d\u503c\u5219\u662f\u6307\u5b57\u7b26\u4e32\u7684\u524d\u7f00\u548c\u540e\u7f00\u7684\u6700\u957f\u76f8\u7b49\u524d\u540e\u7f00\u957f\u5ea6\u3002\u4e0b\u9762\u4ee5&#039;ababa&#039;\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e:&#039;a&#039;\u7684\u524d\u7f00\u548c\u540e\u7f00\u90fd\u4e3a\u7a7a\u96c6&#xff0c;\u6700\u957f\u76f8\u7b49\u524d\u540e\u7f00\u957f\u5ea6\u4e3a0\u3002<\/p>\n<hr \/>\n<h4 style=\"background-color:transparent\">2.1\u4ec0\u4e48\u662f\u524d\u7f00\u3001\u540e\u7f00<\/h4>\n<p>\u4ee5\u5b57\u7b26\u4e32 ababa \u4e3a\u4f8b&#xff1a;<\/p>\n<\/p>\n<p>&#x1f449; \u6240\u4ee5&#xff1a;<\/p>\n<p>\u5b57\u7b26\u4e32 &#034;ababa&#034; \u7684\u90e8\u5206\u5339\u914d\u503c &#061; 3<\/p>\n<ul>\n<li>\n<p>\u524d\u7f00&#xff08;\u4e0d\u542b\u81ea\u8eab&#xff09;<\/p>\n<p>a<br \/>\nab<br \/>\naba<br \/>\nabab<\/p>\n<\/li>\n<li>\n<p>\u540e\u7f00&#xff08;\u4e0d\u542b\u81ea\u8eab&#xff09;<\/p>\n<p>baba<br \/>\naba<br \/>\nba<br \/>\na  <\/p>\n<hr \/>\n<h4>2.2\u516c\u5171\u524d\u540e\u7f00<\/h4>\n<p>\u524d\u7f00\u96c6\u5408&#xff1a;{a, ab, aba, abab}<br \/>\n\u540e\u7f00\u96c6\u5408&#xff1a;{a, ba, aba, baba}<\/p>\n<p>\u516c\u5171\u5143\u7d20&#xff1a;<\/p>\n<p>{a, aba}\n<\/li>\n<li>\n<p>\u516c\u5171\u5143\u7d20\u6709\u4e24\u4e2a<\/p>\n<\/li>\n<li>\n<p>\u6700\u957f\u516c\u5171\u524d\u540e\u7f00\u662f &#034;aba&#034;<\/p>\n<\/li>\n<li>\n<p>\u957f\u5ea6\u4e3a 3<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02.3\u6a21\u5f0f\u4e32\u6bcf\u4e2a\u4f4d\u7f6e\u7684 PM \u8868\u662f\u600e\u4e48\u6765\u7684<\/h4>\n<p>\u6a21\u5f0f\u4e32&#xff1a;<\/p>\n<p>a b a b a<\/p>\n<p>\u6211\u4eec\u4e0d\u662f\u4e00\u6b21\u7b97\u6574\u4e2a\u4e32&#xff0c;\u800c\u662f&#xff1a;<\/p>\n<p>\u5bf9\u6a21\u5f0f\u4e32\u7684\u6bcf\u4e00\u4e2a\u201c\u524d\u7f00\u5b50\u4e32\u201d\u5206\u522b\u6c42 PM \u503c<\/p>\n<hr \/>\n<table>\n<tr>\u5b50\u4e32\u524d\u7f00\u540e\u7f00\u6700\u957f\u76f8\u7b49\u524d\u540e\u7f00PM<\/tr>\n<tbody>\n<tr>\n<td>a<\/td>\n<td>\u7a7a\u96c6<\/td>\n<td>\u7a7a\u96c6<\/td>\n<td>\u65e0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>ab<\/td>\n<td>a<\/td>\n<td>b<\/td>\n<td>\u65e0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>aba<\/td>\n<td>a ab<\/td>\n<td>ba a<\/td>\n<td>a<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>abab<\/td>\n<td>a ab aba<\/td>\n<td>bab ab b<\/td>\n<td>ab<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>ababa<\/td>\n<td>a ab aba abab<\/td>\n<td>baba bab ab b<\/td>\n<td>aba<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<p style=\"background-color:transparent\">\u5f97\u5230 PM \u8868<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u6a21\u5f0f\u4e32&#xff1a;<\/td>\n<td>a<\/td>\n<td>b<\/td>\n<td>a<\/td>\n<td>b<\/td>\n<td>a<\/td>\n<\/tr>\n<tr>\n<td>PM\u503c&#xff1a;<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6a21\u5f0f\u4e32: a  b  a  b  a<br \/>\nPM\u503c:   0  0  1  2  3<\/p>\n<p>\u90a3\u4e48&#xff1a;<\/p>\n<p>\u6a21\u5f0f\u4e32&#039;ababa&#039;\u7684\u90e8\u5206\u5339\u914d\u503c\u4e3a00123<\/p>\n<hr \/>\n<h4>2.4 PM \u8868\u5230\u5e95\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;&#xff08;\u91cd\u70b9&#xff09;<\/h4>\n<p>\u5f53\u5339\u914d\u5931\u8d25\u65f6&#xff0c;\u7528 PM \u8868\u51b3\u5b9a\u6a21\u5f0f\u4e32\u5411\u53f3\u79fb\u52a8\u591a\u5c11\u4f4d&#xff0c;\u4ece\u800c\u907f\u514d\u91cd\u590d\u6bd4\u8f83<\/p>\n<\/p>\n<ul><\/ul>\n<hr \/>\n<h3 id=\"3.%20KMP%20%E4%B8%8E%20BF%20%E7%9A%84%E6%A0%B9%E6%9C%AC%E5%8C%BA%E5%88%AB\">3. KMP \u4e0e BF \u7684\u6839\u672c\u533a\u522b<\/h3>\n<table>\n<tr>\u9879\u76eeBF \u7b97\u6cd5KMP \u7b97\u6cd5<\/tr>\n<tbody>\n<tr>\n<td>\u4e3b\u4e32\u6307\u9488<\/td>\n<td>\u4f1a\u56de\u9000<\/td>\n<td>\u4e0d\u56de\u9000<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u5f0f\u4e32\u79fb\u52a8<\/td>\n<td>\u56de\u5230\u8d77\u70b9<\/td>\n<td>\u6309\u89c4\u5f8b\u79fb\u52a8<\/td>\n<\/tr>\n<tr>\n<td>\u5229\u7528\u4fe1\u606f<\/td>\n<td>\u4e0d\u5229\u7528<\/td>\n<td>\u5229\u7528\u5df2\u5339\u914d\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>\u5339\u914d\u6548\u7387<\/td>\n<td>\u4f4e<\/td>\n<td>\u9ad8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3 id=\"4.%20KMP%20%E5%8C%B9%E9%85%8D%E8%BF%87%E7%A8%8B%E5%9B%BE%E8%A7%A3%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89\" style=\"background-color:transparent\"><span style=\"color:#fe2c24\">4. KMP \u5339\u914d\u8fc7\u7a0b\u56fe\u89e3&#xff08;\u91cd\u70b9&#xff09;<\/span><\/h3>\n<p>\u4ecd\u7136\u4f7f\u7528\u76f8\u540c\u793a\u4f8b&#xff1a;<\/p>\n<p>\u4e3b\u4e32 S&#xff1a; a b a b a a b c a<br \/>\n\u6a21\u5f0f P&#xff1a; a b a a b<\/p>\n<hr \/>\n<h4 id=\"%E5%89%8D%E5%87%A0%E6%AD%A5%E5%8C%B9%E9%85%8D\">\u524d\u51e0\u6b65\u5339\u914d<\/h4>\n<p>S: a b a b a a b c a<br \/>\nP: a b a a b<br \/>\n   \u2191 \u2191 \u2191<\/p>\n<p>\u524d\u4e09\u4e2a\u5b57\u7b26\u6210\u529f\u5339\u914d\u3002<\/p>\n<hr \/>\n<h4 id=\"%E5%8F%91%E7%94%9F%E5%A4%B1%E9%85%8D\">\u53d1\u751f\u5931\u914d<\/h4>\n<p>S[3] &#061; b<br \/>\nP[3] &#061; a \u2192 \u5931\u914d<\/p>\n<hr \/>\n<h4 id=\"BF%20%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E5%BC%8F%EF%BC%88%E5%AF%B9%E6%AF%94%EF%BC%89\">BF \u7684\u5904\u7406\u65b9\u5f0f&#xff08;\u5bf9\u6bd4&#xff09;<\/h4>\n<p>\u6a21\u5f0f\u4e32\u6574\u4f53\u53f3\u79fb\u4e00\u4f4d \u4ece P[0] \u91cd\u65b0\u5f00\u59cb\u6bd4\u8f83 <\/p>\n<hr \/>\n<h4 id=\"KMP%20%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E5%BC%8F%EF%BC%88%E5%85%B3%E9%94%AE%EF%BC%89\"><span style=\"color:#fe2c24\">KMP \u7684\u5904\u7406\u65b9\u5f0f&#xff08;\u5173\u952e&#xff09;<\/span><\/h4>\n<p>\u4e0d\u56de\u9000\u4e3b\u4e32\u6307\u9488&#xff0c;<br \/>\n\u5229\u7528\u5df2\u5339\u914d\u5b50\u4e32\u4e2d<br \/>\n\u201c\u524d\u7f00\u548c\u540e\u7f00\u7684\u516c\u5171\u90e8\u5206\u201d&#xff0c;<br \/>\n\u5c06\u6a21\u5f0f\u4e32\u79fb\u52a8\u5230\u4ecd\u53ef\u80fd\u5339\u914d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u793a\u610f&#xff1a;<\/p>\n<p>S: a b a b a a b c a<br \/>\nP:     a b a a b<\/p>\n<hr \/>\n<h4 id=\"%E6%9C%AC%E8%B4%A8%E7%90%86%E8%A7%A3%EF%BC%88%E9%9D%9E%E5%B8%B8%E9%87%8D%E8%A6%81%EF%BC%89\">\u672c\u8d28\u7406\u89e3<\/h4>\n<ul>\n<li>\n<p>\u5df2\u7ecf\u5339\u914d\u7684\u5b57\u7b26\u4e2d\u4e00\u5b9a\u5305\u542b\u67d0\u79cd\u91cd\u590d\u7ed3\u6784<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u4e9b\u7ed3\u6784\u51b3\u5b9a\u4e86&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u54ea\u4e9b\u4f4d\u7f6e\u4e00\u5b9a\u4e0d\u53ef\u80fd\u5339\u914d<\/p>\n<\/li>\n<li>\n<p>\u54ea\u4e9b\u4f4d\u7f6e\u4ecd\u6709\u53ef\u80fd\u5339\u914d<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u56e0\u6b64\u53ef\u4ee5\u8df3\u8fc7\u4e0d\u5fc5\u8981\u7684\u6bd4\u8f83<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3 style=\"background-color:transparent\">5. KMP \u7b97\u6cd5\u2014\u2014\u5229\u7528 PM \u8868\u8fdb\u884c\u5339\u914d&#xff08;\u5b8c\u6574\u8fc7\u7a0b&#xff09;<\/h3>\n<h4>\u7b2c\u4e00\u8d9f\u5339\u914d<\/h4>\n<p>\u4e3b\u4e32&#xff1a;       a b a b c a b c a c b a b<br \/>\n\u6a21\u5f0f\u4e32&#xff1a;     a b c a c<br \/>\n            \u2191 \u2191<\/p>\n<p>a &#061;&#061; a \u2713<\/p>\n<p>b &#061;&#061; b \u2713<\/p>\n<p>a !&#061; c \u2717 \u2192 \u5931\u914d<\/p>\n<ul><\/ul>\n<hr \/>\n<h4>\u5df2\u5339\u914d\u5b57\u7b26\u6570<\/h4>\n<p>\u5df2\u5339\u914d &#061; 2 &#xff08;&#034;ab&#034;&#xff09;<\/p>\n<hr \/>\n<h4>\u67e5 PM \u8868<\/h4>\n<ul>\n<li>\n<p>\u6700\u540e\u4e00\u4e2a\u5339\u914d\u5b57\u7b26\u662f &#039;b&#039;<\/p>\n<\/li>\n<li>\n<p>&#039;b&#039; \u5bf9\u5e94\u7684\u4f4d\u7f6e\u662f\u7b2c 2 \u4f4d<\/p>\n<\/li>\n<li>\n<p>PM \u503c &#061; 0<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4><span style=\"color:#fe2c24\">\u5173\u952e\u516c\u5f0f<\/span><\/h4>\n<p><span style=\"color:#fe2c24\">\u6a21\u5f0f\u4e32\u53f3\u79fb\u4f4d\u6570 &#061; \u5df2\u5339\u914d\u5b57\u7b26\u6570 \u2212 \u5bf9\u5e94 PM \u503c<\/span><\/p>\n<p>\u53f3\u79fb\u4f4d\u6570 &#061; 2 \u2212 0 &#061; 2<\/p>\n<hr \/>\n<h4>\u53f3\u79fb\u540e\u72b6\u6001<\/h4>\n<p>\u4e3b\u4e32:      a b  a b c a b c a c b a b<br \/>\n\u6a21\u5f0f\u4e32:         a b c a c<\/p>\n<p><span style=\"color:#fe2c24\">\u00a0\u6ce8\u610f&#xff1a;\u4e3b\u4e32\u4e0d\u56de\u9000<\/span><\/p>\n<hr \/>\n<h4>\u7b2c\u4e8c\u8d9f\u5339\u914d<\/h4>\n<p>\u7ee7\u7eed\u4ece\u5f53\u524d\u4f4d\u7f6e\u6bd4\u8f83&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u91cd\u65b0\u6bd4\u8f83<\/p>\n<\/li>\n<li>\n<p>\u82e5\u518d\u6b21\u5931\u914d&#xff0c;\u7ee7\u7eed\u6309\u540c\u6837\u89c4\u5219\u67e5 PM \u8868\u3001\u8ba1\u7b97\u53f3\u79fb\u4f4d\u6570<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u5bf9BF\u548cKMP\u7b97\u6cd5\u7684\u672c\u8d28\u7406\u89e3<\/h4>\n<h5>BF \u7b97\u6cd5\u7684\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u5931\u914d\u540e\u76f4\u63a5\u5168\u90e8\u63a8\u5012\u91cd\u6765<\/p>\n<\/li>\n<li>\n<p>\u5df2\u7ecf\u5339\u914d\u7684\u4fe1\u606f\u5b8c\u5168\u6d6a\u8d39<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>KMP&#xff08;PM \u8868&#xff09;\u7684\u601d\u60f3<\/h5>\n<ul>\n<li>\n<p>\u5df2\u5339\u914d\u7684\u90a3\u4e00\u90e8\u5206\u91cc<br \/>\n\u5df2\u7ecf\u5305\u542b\u4e86\u201c\u524d\u7f00 &#061; \u540e\u7f00\u201d\u7684\u7ed3\u6784\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u4e9b\u7ed3\u6784\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u67d0\u4e9b\u5bf9\u9f50\u65b9\u5f0f\u4e00\u5b9a\u4e0d\u53ef\u80fd\u6210\u529f<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u76f4\u63a5\u8df3\u8fc7<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>PM \u8868\u7684\u610f\u4e49<\/h5>\n<p>PM \u8868\u544a\u8bc9\u6211\u4eec&#xff1a;<br \/>\n\u5728\u5931\u914d\u65f6&#xff0c;\u6a21\u5f0f\u4e32\u6700\u591a\u80fd\u5411\u53f3\u6ed1\u591a\u5c11&#xff0c;\u800c\u4e0d\u6f0f\u6389\u4efb\u4f55\u53ef\u80fd\u7684\u5339\u914d<\/p>\n<hr \/>\n<h3 id=\"5.%20KMP%20%E7%AE%97%E6%B3%95%E7%9A%84%E4%BC%98%E5%8A%BF\">6. KMP \u7b97\u6cd5\u7684\u4f18\u52bf<\/h3>\n<li>\n<p>\u4e3b\u4e32\u6307\u9488\u53ea\u5411\u524d\u79fb\u52a8<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e2a\u5b57\u7b26\u6700\u591a\u6bd4\u8f83\u6709\u9650\u6b21\u6570<\/p>\n<\/li>\n<li>\n<p>\u6574\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n &#043; m)<\/p>\n<\/li>\n<hr \/>\n<h3 id=\"6.%20%E5%B0%8F%E7%BB%93%EF%BC%88%E8%87%AA%E7%84%B6%E5%BC%95%E5%87%BA%20next%EF%BC%89\">7. \u5c0f\u7ed3<\/h3>\n<p>KMP \u7b97\u6cd5\u7684\u9ad8\u6548\u6027\u6765\u6e90\u4e8e&#xff1a;<br \/>\n\u5728\u5339\u914d\u524d&#xff0c;\u5bf9\u6a21\u5f0f\u4e32\u8fdb\u884c\u5206\u6790&#xff0c;<br \/>\n\u8bb0\u5f55\u6bcf\u4e2a\u4f4d\u7f6e\u5931\u914d\u540e\u5e94\u79fb\u52a8\u5230\u54ea\u91cc\u3002<\/p>\n<p>\u8fd9\u4e2a\u5206\u6790\u7ed3\u679c<br \/>\n\u5c31\u4f53\u73b0\u5728 next \/ nextval \u6570\u7ec4 \u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;BF \u7b97\u6cd5&#xff09;1. \u4ec0\u4e48\u662f\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff0c;\u53c8\u79f0\u6734\u7d20\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;Brute Force&#xff0c;\u7b80\u79f0 BF \u7b97\u6cd5&#xff09;&#xff0c;<br \/>\n\u662f\u5b57\u7b26\u4e32\u5339\u914d\u4e2d\u6700\u57fa\u672c\u3001\u6700\u76f4\u89c2\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u662f\u6307\u5728\u4e3b\u4e32\u4e2d\u627e\u5230\u4e0e\u6a21\u5f0f\u4e32(\u60f3\u8981\u641c\u7d22\u7684\u67d0\u4e2a\u5b57\u7b26\u4e32)\u76f8\u540c\u7684\u5b50\u4e32&#xff0c;\u5e76\u8fd4\u56de\u5176\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\u91c7\u7528\u5b9a\u957f\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784&#xff0c;\u7ed9\u51fa\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u4e32\u64cd\u4f5c\u7684\u66b4\u529b\u5339\u914d\u7b97\u6cd5\u3002\u95ee\u9898\u63cf\u8ff0&amp;#xff<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,1813,427],"topic":[],"class_list":["post-65808","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/65808.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;BF \u7b97\u6cd5&#xff09;1. \u4ec0\u4e48\u662f\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff0c;\u53c8\u79f0\u6734\u7d20\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;Brute Force&#xff0c;\u7b80\u79f0 BF \u7b97\u6cd5&#xff09;&#xff0c; \u662f\u5b57\u7b26\u4e32\u5339\u914d\u4e2d\u6700\u57fa\u672c\u3001\u6700\u76f4\u89c2\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u662f\u6307\u5728\u4e3b\u4e32\u4e2d\u627e\u5230\u4e0e\u6a21\u5f0f\u4e32(\u60f3\u8981\u641c\u7d22\u7684\u67d0\u4e2a\u5b57\u7b26\u4e32)\u76f8\u540c\u7684\u5b50\u4e32&#xff0c;\u5e76\u8fd4\u56de\u5176\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\u91c7\u7528\u5b9a\u957f\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784&#xff0c;\u7ed9\u51fa\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u4e32\u64cd\u4f5c\u7684\u66b4\u529b\u5339\u914d\u7b97\u6cd5\u3002\u95ee\u9898\u63cf\u8ff0&amp;#xff\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/65808.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-25T09:56:55+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65808.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/65808.html\",\"name\":\"KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-25T09:56:55+00:00\",\"dateModified\":\"2026-01-25T09:56:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/65808.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/65808.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65808.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"KMP\u7b97\u6cd5\uff08\u4e00\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/65808.html","og_locale":"zh_CN","og_type":"article","og_title":"KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;BF \u7b97\u6cd5&#xff09;1. \u4ec0\u4e48\u662f\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5\u7b80\u5355\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff0c;\u53c8\u79f0\u6734\u7d20\u6a21\u5f0f\u5339\u914d\u7b97\u6cd5&#xff08;Brute Force&#xff0c;\u7b80\u79f0 BF \u7b97\u6cd5&#xff09;&#xff0c; \u662f\u5b57\u7b26\u4e32\u5339\u914d\u4e2d\u6700\u57fa\u672c\u3001\u6700\u76f4\u89c2\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u662f\u6307\u5728\u4e3b\u4e32\u4e2d\u627e\u5230\u4e0e\u6a21\u5f0f\u4e32(\u60f3\u8981\u641c\u7d22\u7684\u67d0\u4e2a\u5b57\u7b26\u4e32)\u76f8\u540c\u7684\u5b50\u4e32&#xff0c;\u5e76\u8fd4\u56de\u5176\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\u91c7\u7528\u5b9a\u957f\u987a\u5e8f\u5b58\u50a8\u7ed3\u6784&#xff0c;\u7ed9\u51fa\u4e00\u79cd\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u4e32\u64cd\u4f5c\u7684\u66b4\u529b\u5339\u914d\u7b97\u6cd5\u3002\u95ee\u9898\u63cf\u8ff0&amp;#xff","og_url":"https:\/\/www.wsisp.com\/helps\/65808.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-25T09:56:55+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/65808.html","url":"https:\/\/www.wsisp.com\/helps\/65808.html","name":"KMP\u7b97\u6cd5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-25T09:56:55+00:00","dateModified":"2026-01-25T09:56:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/65808.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/65808.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/65808.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"KMP\u7b97\u6cd5\uff08\u4e00\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=65808"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65808\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=65808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=65808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=65808"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=65808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}