{"id":683,"date":"2020-03-21T10:39:53","date_gmt":"2020-03-21T02:39:53","guid":{"rendered":"http:\/\/kylelv.com\/?p=683"},"modified":"2020-03-21T10:39:53","modified_gmt":"2020-03-21T02:39:53","slug":"pkucpc2011-fhamilton-circles-%e7%9f%a9%e9%98%b5%e4%b9%98%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=683","title":{"rendered":"PKUCPC2011 F:Hamilton Circles &#8212; \u77e9\u9635\u4e58\u6cd5"},"content":{"rendered":"\n<h2 class=\"has-text-align-center wp-block-heading\">F:Hamilton Circles<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:\u00a01000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a065536kB<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>Bob has a cuboid of size 2 \u00d7 2 \u00d7\u00a0<em>n<\/em>. Consider every 1 \u00d7 1 \u00d7 1 grid of the cuboid as a vertex and there is an edge between two vertices if and only if the corresponding grids have a common surface. How many hamilton cycles are in this graph? A hamilton cycle is a cycle which visits each vertex exactly once and returns to the starting vertex at last.<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>The first line contains an integer\u00a0<em>T<\/em>(<em>T<\/em>\u00a0&lt; 100) indicating the number of test cases.<br>In each test case, there is an single line containing an integer\u00a0<em>n<\/em>(1 \u2264\u00a0<em>n<\/em>\u00a0\u2264 1000000000). \u3000<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>For each test case, print the case number and the number of hamilton cycles in a single line. The answer may be very large, so you should divide this answer by 1000000007 and just output the remainder instead. Please follow the format of the sample output.<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4\n1\n2\n3\n10<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Case 1: 1\nCase 2: 6\nCase 3: 22\nCase 4: 221542<\/pre>\n\n\n\n<p><strong>\u9898\u76ee\u5927\u610f\uff1a<\/strong><\/p>\n\n\n\n<p>\u7ed9\u5b9a2*2*n\u7684\u7acb\u4f53\u7f51\u683c\u56fe\uff0c\uff08\u4e5f\u53ef\u4ee5\u770b\u6210n\u4e2a1*1*1\u4f9d\u6b21\u76f8\u8fde\u7684\u6b63\u65b9\u4f53\u6240\u6709\u9876\u70b9\u6784\u6210\u7684\u56fe\uff09\u3002\u6211\u4eec\u89c4\u5b9a\uff0c\u5f53\u4e14\u4ec5\u5f53\u4e24\u4e2a\u70b9\u5b58\u5728\u4e8e\u540c\u4e00\u4e2a\u6b63\u65b9\u4f53\u4e2d\u4e14\u76f8\u8fde\uff0c\u8fd9\u4e24\u4e2a\u70b9\u5728\u7f51\u683c\u56fe\u4e2d\u624d\u5b58\u5728\u4e00\u6761\u8fb9\u3002\u6c42\u8fd9\u6837\u7684\u7f51\u683c\u56fe\u4e2d\u4e0d\u540c\u7684\u54c8\u5bc6\u987f\u56de\u8def\u6570\uff0c\u7b54\u6848\u5bf91000000007\u53d6\u6a21\u3002\uff081 \u2264 n \u2264 1000000000\uff09<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6ce8\uff1a\u54c8\u5bc6\u987f\u56de\u8def\u662f\u6307\u7531\u67d0\u4e00\u8d77\u70b9\u51fa\u53d1\u5e76\u8fd4\u56de\u8be5\u70b9\u7684\u8def\u5f84\uff0c\u9014\u4e2d\u7ecf\u8fc7\u6240\u6709\u5176\u4ed6\u8282\u70b9\u4e14\u53ea\u7ecf\u8fc7\u4e00\u6b21\u3002<\/p>\n\n\n\n<p><strong>\u9898\u76ee\u89e3\u6790\uff1a<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6211\u4eec\u53ef\u4ee5\u9996\u5148\u6839\u636e\u54c8\u5bc6\u987f\u56de\u8def\u7684\u6027\u8d28\u77e5\u9053\uff0c\u6211\u4eec\u53ea\u9700\u8981\u6ee1\u8db3\u6bcf\u4e2a\u70b9\u8fde\u63a5\u4e14\u4ec5\u8fde2\u6761\u8fb9\uff0c\u5e76\u6784\u6210\u901a\u8def\u5373\u53ef\u3002\u5373\u53d8\u6210\u6c42\u4e0d\u540c\u8fde\u8fb9\u65b9\u5f0f\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u53d1\u73b0\uff0c\u8be5\u56fe\u5177\u6709\u8f83\u5f3a\u5206\u5c42\u6027\u8d28\uff0c\u5373\u53ef\u4ee5\u53d8\u6210\u5c42\u5185\u8fde\u63a5\u65b9\u5f0f\u548c\u76f8\u90bb\u4e24\u5c42\u4e4b\u95f4\u7684\u8fde\u63a5\u65b9\u5f0f\u3002\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u8f83\u4e3a\u81ea\u7136\u7684\u60f3\u5230\u5229\u7528\u9012\u63a8\u7684\u65b9\u5f0f\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u65b0\u52a0\u4e00\u5c42\u70b9\u4e4b\u540e\u7684\u72b6\u6001\u8f6c\u79fb\u3002\u4e5f\u5c31\u662f\u6211\u4eec\u5047\u5b9a\u524dk\u5c42\u6784\u6210\u4e86\u5408\u6cd5\u7684\u54c8\u5bc6\u987f\u56de\u8def\uff0c\u65b0\u52a0\u4e00\u5c42\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u4e14\u4ec5\u9700\u8981\u5220\u9664\u7b2ck\u5c42\u90e8\u5206\u8fde\u8fb9\uff0c\u8fde\u5411k+1\u5c42\uff0c\u5e76\u5728k+1\u5c42\u5185\u5408\u7406\u8fde\u63a5\u6784\u6210\u5408\u6cd5\u65b9\u6848\u3002\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u53d1\u73b0\uff0c\u5982\u679c\u4e24\u5c42\u4e4b\u95f4\u7684\u8fde\u8fb9\u786e\u5b9a\u7684\u8bdd\uff0c\u6700\u540e\u4e00\u5c42\u7684\u5408\u6cd5\u8fde\u8fb9\u65b9\u6848\u662f\u5b58\u5728\u4e14\u552f\u4e00\u7684\u3002\u90a3\u4e48\u4e5f\u5c31\u53d8\u6210\u4e86\u4ece\u7b2ck\u5c42\u5220\u9664\u67d0\u4e9b\u8fb9\u8f6c\u79fb\u5230k+1\u5c42\u7edf\u8ba1\u65b9\u6848\u6570\u3002<\/p>\n\n\n\n<p> \u90a3\u4e48\u6211\u4eec\u5c31\u8003\u8651\u6700\u540e\u4e00\u5c42\u7684\u6240\u6709\u5408\u6cd5\u72b6\u6001\u3002\u51717\u79cd\uff0c\u5176\u4e2d\u7b2c\u4e00\u79cd\u5f53\u4e14\u4ec5\u5f53n=1\u65f6\u6210\u7acb\uff0c\u5176\u4ed6\u4e3an>1\u65f6\u6210\u7acb\u3002 <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"130\" src=\"http:\/\/kylelv.com\/wp-content\/uploads\/2020\/03\/QQ20200321-103836@2x-1024x130.png\" alt=\"\" class=\"wp-image-685\" srcset=\"https:\/\/blog.kylelv.com\/wp-content\/uploads\/2020\/03\/QQ20200321-103836@2x-1024x130.png 1024w, https:\/\/blog.kylelv.com\/wp-content\/uploads\/2020\/03\/QQ20200321-103836@2x-300x38.png 300w, https:\/\/blog.kylelv.com\/wp-content\/uploads\/2020\/03\/QQ20200321-103836@2x-768x97.png 768w, https:\/\/blog.kylelv.com\/wp-content\/uploads\/2020\/03\/QQ20200321-103836@2x.png 1182w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u6211\u4eec\u8003\u8651\u72b6\u6001\u8f6c\u79fb\uff0c\u53ef\u4ee5\u53d1\u73b0\u540c\u65f6\u5220\u9664\u76f8\u90bb\u4e24\u6761\u8fb9\u4e0d\u5408\u6cd5\uff0c\u5176\u4ed6\u72b6\u6001\u5168\u90e8\u5408\u6cd5\uff0c\u5373\u53ef\u4ee5\u5f97\u5230k+1\u5c42\u7684\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u53ef\u4ee5\u81ea\u7136\u7684\u4f7f\u7528dp\u8fdb\u884c\u95ee\u9898\u6c42\u89e3\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53d1\u73b0n\u7684\u8303\u56f4\u975e\u5e38\u5927\uff0c\u6240\u4ee5\u9700\u8981\u8fdb\u884c\u4f18\u5316\u3002\u6211\u4eec\u53d1\u73b0\u72b6\u6001\u6570\u662f\u975e\u5e38\u5c11\u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528\u77e9\u9635\u4e58\u6cd5\u52a0\u901f\u6c42\u89e3\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(7<sup>3<\/sup>log n)<\/p>\n\n\n\n<p><strong>\u4ee3\u7801\u5b9e\u73b0\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;string>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define mod 1000000007\n#define ll long long\n#define N 100010\ninline int rd(){\n    int x=0,f=1;char ch=getchar();\n    while(ch&lt;'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}\n    while(ch>='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\n    return x*f;\n}\nstruct qaz{\n    ll a&#91;7]&#91;7];\n    qaz(){\n        memset(a,0,sizeof(a));\n    }\n    qaz operator *(const qaz &amp;b){\n        qaz c;\n        for(int k=0;k&lt;7;++k)\n            for(int i=0;i&lt;7;++i)\n                for(int j=0;j&lt;7;++j)\n                    (c.a&#91;i]&#91;j]+=a&#91;i]&#91;k]*b.a&#91;k]&#91;j])%=mod;\n        return c;\n    }\n}I,A,ans;\nint T,n;\nqaz ksm(qaz A,int b){\n    qaz ta=I;\n    while(b){\n        if(b&amp;1) ta=ta*A;\n        A=A*A;b>>=1;\n    }\n    return ta;\n}\nvoid INIT(){\n    for(int i=0;i&lt;7;++i) I.a&#91;i]&#91;i]=1;\n    A.a&#91;0]&#91;1]=A.a&#91;0]&#91;2]=A.a&#91;0]&#91;3]=A.a&#91;0]&#91;4]=A.a&#91;0]&#91;5]=A.a&#91;0]&#91;6]=1;\n    A.a&#91;1]&#91;1]=A.a&#91;1]&#91;3]=A.a&#91;1]&#91;5]=1;\n    A.a&#91;2]&#91;2]=A.a&#91;2]&#91;4]=A.a&#91;2]&#91;6]=1;\n    A.a&#91;3]&#91;2]=A.a&#91;3]&#91;4]=A.a&#91;3]&#91;5]=A.a&#91;3]&#91;6]=1;\n    A.a&#91;4]&#91;1]=A.a&#91;4]&#91;3]=A.a&#91;4]&#91;5]=A.a&#91;4]&#91;6]=1;\n    A.a&#91;5]&#91;2]=A.a&#91;5]&#91;3]=A.a&#91;5]&#91;4]=A.a&#91;5]&#91;6]=1;\n    A.a&#91;6]&#91;1]=A.a&#91;6]&#91;3]=A.a&#91;6]&#91;4]=A.a&#91;6]&#91;5]=1;\n}\nll Ans;\nint main(){\n    INIT();\n    T=rd();\n    for(int _=1;_&lt;=T;++_){\n        n=rd();\n        ans=ksm(A,n-1);\n        Ans=0;\n        for(int i=0;i&lt;7;++i) Ans+=ans.a&#91;0]&#91;i];\n        printf(\"Case %d: %lld\\n\",_,Ans%mod);\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>F:Hamilton Circles \u603b\u65f6\u95f4\u9650\u5236:\u00a01000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a065536kB \u63cf\u8ff0 Bob h [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8,73],"class_list":["post-683","post","type-post","status-publish","format-standard","hentry","category-poj","tag-8","tag-73"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=683"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}