{"id":96,"date":"2023-03-28T17:04:45","date_gmt":"2023-03-28T09:04:45","guid":{"rendered":"https:\/\/solost.cn\/?p=96"},"modified":"2023-03-28T17:04:45","modified_gmt":"2023-03-28T09:04:45","slug":"189","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=96","title":{"rendered":"Trie\u6811"},"content":{"rendered":"<pre><code class=\"lang-cpp\">int son[N][26], cnt[N], idx;\n\/\/ 0\u53f7\u70b9\u65e2\u662f\u6839\u8282\u70b9\uff0c\u53c8\u662f\u7a7a\u8282\u70b9\n\/\/ son[][]\u5b58\u50a8\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9\n\/\/ cnt[]\u5b58\u50a8\u4ee5\u6bcf\u4e2a\u8282\u70b9\u7ed3\u5c3e\u7684\u5355\u8bcd\u6570\u91cf\n\n\/\/ \u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\nvoid insert(char *str)\n{\n    int p = 0;\n    for (int i = 0; str[i]; i ++ )\n    {\n        int u = str[i] - &#039;a&#039;;\n        if (!son[p][u]) son[p][u] = ++ idx;\n        p = son[p][u];\n    }\n    cnt[p] ++ ;\n}\n\n\/\/ \u67e5\u8be2\u5b57\u7b26\u4e32\u51fa\u73b0\u7684\u6b21\u6570\nint query(char *str)\n{\n    int p = 0;\n    for (int i = 0; str[i]; i ++ )\n    {\n        int u = str[i] - &#039;a&#039;;\n        if (!son[p][u]) return 0;\n        p = son[p][u];\n    }\n    return cnt[p];\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>int son[N][26], cnt[N], idx; \/\/ 0\u53f7\u70b9\u65e2\u662f\u6839\u8282\u70b9\uff0c\u53c8\u662f\u7a7a\u8282\u70b9 \/\/ son[][]\u5b58\u50a8\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9 \/\/ cnt[]\u5b58\u50a8\u4ee5\u6bcf\u4e2a\u8282\u70b9\u7ed3\u5c3e\u7684\u5355\u8bcd\u6570\u91cf \/\/ \u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32 void insert(char *str) { int p = 0; for (int i = 0; str[i]; i ++ ) { int u = str[i] - &#039;a&#039;; if (!son[p][u]) son[p][u] = ++ idx; p = son[p][u]; } cnt[p] ++ ; } \/\/ \u67e5\u8be2\u5b57\u7b26\u4e32\u51fa\u73b0\u7684\u6b21\u6570 int query(char *str) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[42,43],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-acm","tag-trie","tag-43"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}