{"id":3296,"date":"2024-05-20T04:50:47","date_gmt":"2024-05-19T20:50:47","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=3296"},"modified":"2024-05-20T23:20:25","modified_gmt":"2024-05-20T15:20:25","slug":"infinite-monkey-theorem","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/infinite-monkey-theorem\/","title":{"rendered":"\u6b4c\u5531\u738b\u56fd"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/www.luogu.com.cn\/problem\/P4548\">https:\/\/www.luogu.com.cn\/problem\/P4548<\/a><\/li>\n<li><a href=\"https:\/\/www.luogu.com.cn\/problem\/P6835\">https:\/\/www.luogu.com.cn\/problem\/P6835<\/a><\/li>\n<li><a href=\"https:\/\/vjudge.net\/problem\/HDU-3992\">https:\/\/vjudge.net\/problem\/HDU-3992<\/a><\/li>\n<li><a href=\"https:\/\/vjudge.net\/problem\/Gym-104551B\">https:\/\/vjudge.net\/problem\/Gym-104551B<\/a><\/li>\n<li><a href=\"https:\/\/vjudge.net\/problem\/HDU-3689\">https:\/\/vjudge.net\/problem\/HDU-3689<\/a><\/li>\n<li><a href=\"https:\/\/leetcode.cn\/problems\/find-all-possible-stable-binary-arrays-ii\/description\/\">https:\/\/leetcode.cn\/problems\/find-all-possible-stable-binary-arrays-ii\/description\/<\/a><\/li>\n<\/ul>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\n#include &amp;lt;lastweapon\/string&amp;gt;\n#include &amp;lt;lastweapon\/number&amp;gt;\nusing namespace lastweapon;\n\nint Z;\n\nint f() {\n\n&lt;pre&gt;&lt;code&gt;int n; RD(n); VI P; DO(n) P.PB(RD());\nauto pi = kmp(P);\n\nInt z = 0; while (n) {\n    z += pow(Int(Z), n); n = pi&#x5B;n-1] + 1;\n}\nreturn z;\n&lt;\/code&gt;&lt;\/pre&gt;\n\n}\n\nint main() {\n\n#ifndef ONLINE_JUDGE\n    freopen(&amp;quot;in.txt&amp;quot;, &amp;quot;r&amp;quot;, stdin);\n    \/\/freopen(&amp;quot;out.txt&amp;quot;, &amp;quot;w&amp;quot;, stdout);\n#endif\n\n&lt;pre&gt;&lt;code&gt;MOD = 10000; RD(Z); Rush {\n    printf(&amp;amp;quot;%04d\\n&amp;amp;quot;, f());\n}\n&lt;\/code&gt;&lt;\/pre&gt;\n\n}\n\n<\/pre>\n<p>\u7ecf\u5178\u95ee\u9898\uff01\u6700\u540e\u4ee3\u7801\u975e\u5e38\u7b80\u5355\uff0c\u4f46\u5e76\u4e0d\u662f\u5341\u5206\u663e\u7136\uff0c\u4ee4\u4eba\u6d6e\u60f3\u8054\u7fe9\u3002<br \/>\n\u9996\u5148\u6700\u6734\u7d20\u7684\u81ea\u52a8\u673a dp \u4e5f\u662f\u53ef\u4ee5\u63a8\u51fa\u6765\u7684\uff01\u76f4\u63a5\u8bbe\u72b6\u6001 f[i] \u8868\u793a\u5339\u914d\u4e0a\u524d i \u4e2a\u5b57\u7b26\u4e4b\u540e\u5269\u4f59\u7684\u671f\u671b\u6b65\u6570\u3002<br \/>\n\u5229\u7528 trans \u6570\u7ec4\u5efa\u7acb\u8f6c\u79fb\u65b9\u7a0b\uff0c\u4f46\u662f\u8fd9\u4e2a\u65b9\u7a0b\u662f\u6709\u73af\u7684\uff0c\u6734\u7d20\u505a\u6cd5\u9ad8\u65af\u6d88\u5143 O(n3)\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u8fdb\u4e00\u6b65\u6316\u6398\u8fd9\u7c7b\u77e9\u9635\u7684\u6027\u8d28\u3002<br \/>\n\u7c7b\u4f3c<a href=\"https:\/\/www.shuizilong.com\/house\/archives\/codechef-october-challenge-2012\/\">\u8c03\u8272\u677f\u90a3\u4e2a\u9898<\/a>\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5dee\u5206\u4e4b\u540e\u63a8\u63a8\u63a8\u76f4\u63a5\u5f97\u5230\u4e0a\u9762\u7684 O(n) \u505a\u6cd5\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u6837\u9700\u8981\u4e00\u5b9a\u7684\u4ee3\u6570\u5e95\u529b\uff0c\u53e6\u4e00\u4e2a\u76f8\u5bf9\u66f4\u7b80\u5355\u7684\u505a\u6cd5\u662f\u4f7f\u7528\u6982\u7387\u751f\u6210\u51fd\u6570\uff0c\u4f46\u662f\u8fd9\u4e2a\u505a\u6cd5\u4e5f\u4e0d\u80fd\u5e2e\u52a9\u6211\u4eec\u4e00\u773c\u770b\u51fa\u4e3a\u4ec0\u4e48\u8fd9\u4e2a\u9898\u4f1a\u548c border \u8054\u7cfb\u5982\u6b64\u7d27\u5bc6\u3002<br \/>\n\u66f4\u9ad8\u7ea7\u7684\u505a\u6cd5\u662f\u6784\u9020\u4e00\u4e2a\u516c\u5e73\u535a\u5f08\uff0c\u6765\u4e86\u4e00\u5927\u5806 <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/jag-spring-contest-2015\/\">ASC 42 B<\/a> \u90a3\u79cd\u8d4c\u5c40\uff0c\u6700\u540e\u5c06\u671f\u671b\u6b65\u6570\u7b49\u4ef7\u4e8e\u6e38\u620f\u7ed3\u675f\u65f6\u5269\u4f59\u8d4c\u5f92\u7684\u6536\u76ca\u3002<br \/>\n\u8fd9\u4e2a\u505a\u6cd5\u80cc\u540e\u7684\u7406\u8bba\u57fa\u7840\u662f\u9785\u8bba\uff0c\u6709\u65f6\u80fd\u591f\u5e2e\u6211\u4eec\u4e00\u773c\u770b\u51fa\u8fd9\u7c7b\u9898\u7684\u7b54\u6848\u3002<\/p>\n<h2>dp<\/h2>\n<h2>\u6982\u7387\u751f\u6210\u51fd\u6570<\/h2>\n<h2>\u9785\u8bba<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.luogu.com.cn\/problem\/P4548 https:\/\/www.luogu.com.cn\/problem\/P6835 https:\/\/vjudge.net\/problem\/HDU-3992 https:\/\/vjudge.net\/problem\/Gym-104551B https:\/\/vjudge.net\/problem\/HDU-3689 https:\/\/leetcode.cn\/problems\/find-all-possible-stable-binary-arrays-ii\/description\/ #include &amp;lt;lastweapon\/string&amp;gt; #include &amp;lt;lastweapon\/number&amp;gt; using namespace lastweapon; int Z; int f() { &lt;pre&gt;&lt;code&gt;int n; RD(n); VI P; DO(n) P.PB(RD()); auto pi = kmp(P); Int z = 0; while (n) { z += pow(Int(Z), n); n = pi&#x5B;n-1] + 1; } return z; &lt;\/code&gt;&lt;\/pre&gt; } int main() { #ifndef ONLINE_JUDGE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-3296","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-Ra","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=3296"}],"version-history":[{"count":6,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3296\/revisions"}],"predecessor-version":[{"id":3302,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3296\/revisions\/3302"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=3296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=3296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=3296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}