{"id":43,"date":"2020-03-22T20:43:18","date_gmt":"2020-03-22T12:43:18","guid":{"rendered":"http:\/\/47.103.223.234:100\/?p=43"},"modified":"2020-03-23T17:01:17","modified_gmt":"2020-03-23T09:01:17","slug":"tire%e5%ad%97%e5%85%b8%e6%a0%91","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/03\/22\/tire%e5%ad%97%e5%85%b8%e6%a0%91\/","title":{"rendered":"Trie\u5b57\u5178\u6811"},"content":{"rendered":"<p>Trie\u6811\u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u53c8\u79f0\u5b57\u5178\u6811\u3002\u7528\u6765\u5b58\u653e\u5927\u91cf\u7684\u5b57\u7b26\u4e32\u3002\u501f\u52a9\u4e8e\u5b83\u4eec\u7684\u516c\u5171\u524d\u7f00\u6765\u51cf\u5c11\u5b58\u50a8\u7a7a\u95f4\u548c\u8bbf\u95ee\u65f6\u95f4\uff0c\u6548\u7387\u5f88\u9ad8\u3002<br \/>\n<img src=\"http:\/\/47.103.223.234:100\/wp-content\/uploads\/2020\/03\/419080f406db2fd63b1d2aad9cd70d77-300x300.png\" alt=\"\" \/><br \/>\n\u4e0d\u540c\u4e8e\u4e00\u822c\u7684\u6811\u5f62\u7ed3\u6784\uff0cTrie\u7684\u6570\u636e\u662f\u5b58\u653e\u5728\u8fb9\u4e2d\u800c\u4e0d\u662f\u5b58\u653e\u5728\u70b9\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u66f4\u5feb\u7684\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u5229\u7528\u4e0b\u4e00\u4e2a\u5b57\u7b26\u7684\u6570\u636e\u5185\u5bb9\u6765\u4f5c\u4e3a\u8bbf\u95ee\u7684\u4e0b\u6807\u3002<br \/>\n\u4f8b\u5982\uff0c\u518d\u4e0a\u56fe\u4e2d\uff0cTrie[0]['a'] = 1,Trie[0]['b'] = 2,Trie[1]['h'] = 12;\u5f53\u60f3\u8981\u77e5\u9053\u6709\u6ca1\u6709\u4ee5c\u5f00\u5934\u7684\u5355\u8bcd\u65f6\uff0c\u53ea\u9700\u8bbf\u95ee\u4e0bTrie[0]['c']\u662f\u5426\u4e3a0\u5373\u53ef\u3002<br \/>\n\u6a21\u677f<\/p>\n<pre><code class=\"language-c++\">\/\/\u5b58\u50a8\u5f62\u5f0f\nint Trie[maxn][26];\nint sum[maxn][26];\nint tot = 0;\n\/*Trie[][]\u7684\u503c\u4e3a\u7b2c\u51e0\u4e2a\u7ed3\u70b9\uff0c\u800c\u6570\u636e\u662f\u5b58\u653e\u5728\u8fb9\u4e0a\u7684\uff0csum\u7528\u6765\u6807\u8bb0\u5176\u4ed6\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u6709\u591a\u5c11\u4e2a\u5b57\u7b26\u4e32\u7ecf\u8fc7\u8fd9\u4e2a\u70b9\uff0c\u4ee5\u8be5\u70b9\u4f4d\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u6709\u591a\u5c11\u4e2a\u7b49\u3002*\/<\/code><\/pre>\n<p>\u63d2\u5165(insert)   \u63d2\u5165\u4ee3\u7801\u53ef\u4ee5\u8bf4\u662fTrie\u6811\u7684\u6838\u5fc3\uff01\u52a1\u5fc5\u7406\u89e3\u900f\u5f7b\u3002<\/p>\n<pre><code class=\"language-c++\">void insert(char *s){\n    int root = 0;\n    for (int i=1;i&lt;=len;i++){\n        if (Trie[root][s[i]]==0){\n            Trie[root][s[i]] = ++tot;\n        }\n        root = Trie[root][s[i]];\n    }\n    return;\n}\n<\/code><\/pre>\n<p>\u67e5\u8be2(query)    \u67e5\u8be2\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u6765\u67e5\u627e\u81ea\u5df1\u9700\u8981\u7684\u4e1c\u897f\uff0c\u524d\u7f00\uff0c\u5305\u542b\u8be5\u524d\u7f00\u7684\u5b57\u7b26\u4e32\u4e2a\u6570\u7b49<\/p>\n<pre><code class=\"language-c++\">int query(char *s){\n    int root = 0;\n    int ans = 0;\n    for (int i=1;i&lt;=len;i++){\n        if (Trie[root][s[i]]==0)\n            return 0;\n        Func_ans();  \/\/\u6709\u5173\u64cd\u4f5c\n        root = Trie[root][s[i]];\n    }\n    return ans;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Trie\u6811\u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u53c8\u79f0\u5b57\u5178\u6811\u3002\u7528\u6765\u5b58\u653e\u5927\u91cf\u7684\u5b57\u7b26\u4e32\u3002\u501f\u52a9\u4e8e\u5b83\u4eec\u7684\u516c\u5171\u524d\u7f00\u6765\u51cf\u5c11\u5b58\u50a8\u7a7a\u95f4\u548c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/43"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":8,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":54,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions\/54"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}