{"id":70,"date":"2020-03-23T23:01:32","date_gmt":"2020-03-23T15:01:32","guid":{"rendered":"http:\/\/47.103.223.234:100\/?p=70"},"modified":"2020-03-23T23:19:32","modified_gmt":"2020-03-23T15:19:32","slug":"cf-535d-kmp","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/03\/23\/cf-535d-kmp\/","title":{"rendered":"CF 535D KMP"},"content":{"rendered":"<p>\u9898\u610f\uff1a\u7ed9\u5b9a\u4e00\u5b57\u7b26\u4e32s\uff0c\u548c\u4e00\u4e2a\u4f4d\u7f6e\u6570\u7ec4pos[]\uff0c\u5728\u4e00\u4e2a\u957f\u4e3an\u7684\u7a7a\u5b57\u7b26\u4e32\u4e2d\uff0c\u5728\u6bcf\u4e00\u4e2a\u4f4d\u7f6epos[i]\u5904\u8d34\u4e0as\uff0c\u5f53\u6709\u91cd\u53e0\u65f6\uff0c\u91cd\u53e0\u7684\u90e8\u5206\u5fc5\u987b\u5b8c\u5168\u76f8\u540c\uff0c\u95ee\u6709\u591a\u5c11\u79cd\u6ee1\u8db3\u9898\u610f\u5f97\u5b57\u7b26\u4e32\u3002<br \/>\n\u8f93\u5165\uff1a<br \/>\n\u7b2c\u4e00\u884c\u4e24\u4e2a\u6574\u6570\uff1an m<br \/>\n\u7b2c\u4e8c\u884c\u957f\u4e3a|s|\u7684\u5b57\u7b26\u4e32<br \/>\n\u7b2c\u4e09\u884c\u4e3am\u4e2a\u6574\u6570pos[i]<br \/>\n\u5206\u6790\uff1a\u5728\u8d34\u4e0am\u4e2as\u4e32\u4e4b\u540e\uff0c\u8ba1\u7b97\u5269\u4f59\u7684\u7a7a\u4f4d\u7f6ecnt\uff0c\u8f93\u51fa\u7b54\u684826^cnt\u5373\u53ef\u3002\u90a3\u4e48\u96be\u70b9\u8f6c\u5316\u4e3a\u5224\u65ad\u8fd9m\u4e2as\u4e32\u662f\u5426\u80fd\u591f\u5b8c\u5168\u76f8\u5bb9\u3002<br \/>\n\u65e2\u7136\u8981\u6c42\u6bcf\u4e00\u4e2a\u91cd\u53e0\u7684\u5730\u65b9\u90fd\u8981\u76f8\u540c\uff0c\u5982\u679c\u91cd\u53e0\u7684\u90e8\u5206\u957f\u5ea6\u4e3al\uff0c\u90a3\u5176\u5b9e\u5c31\u662f\u8bf4s\u9700\u6ee1\u8db3s\u7684\u524dl\u4e2a\u5b57\u7b26\u548c\u540el\u4e2a\u5b57\u7b26\u76f8\u7b49\u3002\u95ee\u9898\u8f6c\u5316\u4e3as\u7684\u524di\u4e2a\u5b57\u7b26\u548c\u540ei\u4e2a\u5b57\u7b26\u662f\u5426\u76f8\u7b49\u3002\u6211\u4eec\u77e5\u9053kmp\u7b97\u6cd5\u4e2d\u7684Next[]\u6570\u7ec4\u8868\u793a\u7684\u662f\u524di\u4e2a\u5b57\u7b26\u4e2d\uff0c\u524d\u7f00\u548c\u540e\u7f00\u76f8\u540c\u7684\u6700\u5927\u957f\u5ea6\uff0c\u90a3\u5982\u4f55\u8868\u793a\u51fa\u6240\u6709\u7684\u524d\u7f00\u548c\u540e\u7f00\u76f8\u540c\u7684\u957f\u5ea6\u5462\u3002<br \/>\nNext[|s|]\u8868\u793a\u4e32s\u524d\u7f00\u548c\u540e\u7f00\u76f8\u540c\u7684\u6700\u5927\u957f\u5ea6\uff0c\u5373s[1,2,..Next[|s|]]=s[|s|-Next[|s|]+1,...,|s|],\u800c\u5728\u524dNext[|s|]\u4e2a\u5b57\u7b26\u4e2d\uff0c\u4e5f\u4f1a\u6709s[1,2,..Next[Next[|s|]]]=s[Next[|s|]-Next[Next[|s|]]+1,..,Next[|s|]],\u4ed4\u7ec6\u60f3\u60f3\u8fd9\u4e9b\u5934\u5c3e\u76f8\u7b49\u7684\u5b57\u7b26\u4e32\u548c\u5b50\u4e32\u7684\u5173\u7cfb\uff0c\u5c31\u4f1a\u53d1\u73b0\uff0c\u8fd9\u662f\u4e00\u4e2a\u9012\u5f52\u7684\u8fc7\u7a0b\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u6765\u6c42\u5f97|s|\u6240\u6709\u7684\u524d\u540e\u7f00\u76f8\u540c\u7684\u957f\u5ea6\u3002<br \/>\n\u8bbemark[i]\u8868\u793as\u7684\u524di\u548c\u540ei\u4e2a\u5b57\u7b26\u662f\u5426\u76f8\u540c\uff0c\u5728\u8d34\u7684\u65f6\u5019\u53ea\u9700\u5224\u65ad\u91cd\u53e0\u7684\u90e8\u5206\u662f\u5426\u88abmark\u5373\u53ef\u3002<\/p>\n<pre><code class=\"language-c++\">\/\/#include &lt;bits\/stdc++.h&gt;\n#include &lt;iostream&gt;\n#include &lt;cstdio&gt;\n#include &lt;string.h&gt;\nusing namespace std;\ntypedef long long ll;\nconst int maxn = 1e6+5,mod = 1e9+7;\nll pow_mod(ll a,ll b);       \/\/\u6c42a^b%mod\nchar p[maxn];\nint pos[maxn],Next[maxn],mark[maxn];\nint main(){\n    int n,m,len;\n    scanf (&quot;%d %d %s&quot;,&amp;n,&amp;m,p+1);\n    len = strlen(p+1);\n    for(int i=2,j=0;i&lt;=len;i++){         \/\/Next\u6570\u7ec4\u6c42\u53d6\n        while(j&gt;0 &amp;&amp; p[i]!=p[j+1]) j=Next[j];\n        if(p[i]==p[j+1]) j++;\n        Next[i]=j;\n    }\n    for (int i=len;i;i=Next[i]) mark[i] = 1;    \/\/\u9012\u5f52\u6807\u8bb0mark\n    scanf (&quot;%d&quot;,&amp;pos[1]);\n    for (int i=2;i&lt;=m;i++){                    \/\/\u68c0\u67e5\u662f\u5426\u53ef\u4ee5\u6784\u6210\u6bcd\u4e32\n        scanf (&quot;%d&quot;,&amp;pos[i]);\n        if (pos[i]-pos[i-1]&gt;=len)   continue;\n        if ( pos[i]+len-1&gt;n || mark[len-(pos[i]-pos[i-1])]==0 ){\n            printf(&quot;0&quot;);\n            return 0;\n        }\n    }\n    if(m)   n -= len;\n    for (int i=2;i&lt;=m;i++)                      \/\/\u8ba1\u7b97\u672a\u88ab\u6a21\u5f0f\u4e32\u8986\u76d6\u7684\u4f4d\u7f6e\u7684\u4e2a\u6570\n        n -= pos[i]-pos[i-1]&lt;len?pos[i]-pos[i-1]:len;\n    printf(&quot;%lld&quot;,pow_mod((ll)26,(ll)n));\n    return 0;\n}\nll pow_mod(ll a,ll b){\n    a %= mod;\n    if (a==0)   return 0;\n    ll ans = 1;\n    while (b){\n        if (b&amp;1)    ans = (ans*a)%mod;\n        a = (a*a)%mod;\n        b &gt;&gt;= 1;\n    }\n    return ans%mod;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f\uff1a\u7ed9\u5b9a\u4e00\u5b57\u7b26\u4e32s\uff0c\u548c\u4e00\u4e2a\u4f4d\u7f6e\u6570\u7ec4pos[]\uff0c\u5728\u4e00\u4e2a\u957f\u4e3an\u7684\u7a7a\u5b57\u7b26\u4e32\u4e2d\uff0c\u5728\u6bcf\u4e00\u4e2a\u4f4d\u7f6epos[i]\u5904 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/70"}],"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=70"}],"version-history":[{"count":3,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":73,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/70\/revisions\/73"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}