{"id":72,"date":"2011-03-24T07:49:49","date_gmt":"2011-03-23T23:49:49","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=72"},"modified":"2012-03-03T07:50:01","modified_gmt":"2012-03-02T23:50:01","slug":"sdoi-2009-hh%e5%8e%bb%e6%95%a3%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/sdoi-2009-hh%e5%8e%bb%e6%95%a3%e6%ad%a5\/","title":{"rendered":"[SDOI 2009] HH\u53bb\u6563\u6b65"},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ef\u80fd\u91cd\u8fb9\u4f46\u6ca1\u6709\u81ea\u73af\u7684\u65e0\u5411\u56fe\uff0c\u8981\u6c42\u8ba1\u7b97 A, B \u4e24\u70b9\u4e4b\u95f4\u6b65\u6570\u4e3a t \u7684\u65b9\u6848\u6570\u3002\u7b54\u6848\u6a21 45989\u3002<br \/>\n\uff08\u53ef\u4ee5\u7ecf\u8fc7\u67d0\u4e2a\u70b9\u67d0\u6761\u8fb9\u591a\u6b21\uff0c\u4f46\u662f\u4e0d\u53ef\u4ee5\u7acb\u5373\u6cbf\u7740\u540c\u4e00\u6761\u8fb9\u6298\u8fd4\u3002\uff09<br \/>\n\uff08.. N <= 20, M <= 60, t <= 2^30 ..\uff09\n<!--more--><\/p>\n<h3>Analyse :<\/h3>\n<p>\u7531\u4e8e\u201c\u4e0d\u4f1a\u6cbf\u7740\u540c\u4e00\u6761\u8fb9\u6298\u8fd4\u201d\uff0c\u56e0\u6b64\u4ece A \u70b9\u7ecf\u8fc7 k \u6b65\u5f8c\u7684\u72b6\u6001\u4ec5\u4e0e\u6700\u540e\u4e00\u6b65\u6240\u8d70\u7684\u8fb9\u548c\u5b83\u7684\u65b9\u5411\u6709\u5173\u3002<br \/>\n\u5982\u679c\u5c06\u6bcf\u6761\u65e0\u5411\u8fb9\u62c6\u6210\u4e24\u6761\u6709\u5411\u8fb9\uff0c\u90a3\u4e48\u4ec5\u4e8e\u8fb9\u6709\u5173\u3002<br \/>\nF[i][j] : \u5df2\u7ecf\u8d70\u4e86 i \u6b65\uff0c\u6700\u540e\u4e00\u6b65\u8d70\u8fc7\u7684\u8fb9\u662f i \u7684\u65b9\u6848\u6570\u3002<\/p>\n<pre lang=\"cpp\">\r\n#include <iostream>\r\nusing namespace std;\r\nconst int N = 20, M = 60, MM = 2 * M;\r\nconst int _P = 45989;\r\nstruct Edge{\r\n\tint x, y;\r\n} E[MM];\r\nint n, m, t, a, b;\r\nint ans, mm, x, y;\r\n\r\nstruct matrix{\r\n\tint d[MM][MM];\r\n\tmatrix(){\r\n\t\tmemset(d, 0, sizeof(d));\r\n\t}\r\n} A, C;\r\n\r\nmatrix operator *(const matrix& a, const matrix& b){\r\n\tmatrix c;\r\n\tfor (int i=0;i<mm;i++)\r\n\t\tfor (int j=0;j<mm;j++)\r\n\t\t\tfor (int k=0;k<2*m;k++)\r\n\t\t\t\tc.d[i][j] += a.d[i][k] * b.d[k][j], c.d[i][j] %= _P;\r\n\treturn c;\r\n}\r\n\r\n\r\n\r\nmatrix pow(matrix a, int b){\r\n\tmatrix c;\r\n\tfor (int i = 0; i < mm; i ++)\r\n\t\tc.d[i][i] = 1;\r\n\twhile (b!=0){\r\n\t\tif (b%2==1) c = c * a;\r\n\t\ta = a * a, b \/= 2;\r\n\t}\r\n\treturn c;\r\n}\r\n\r\n\r\n\r\nint main(){\r\n\t\/\/freopen(\"in.txt\", \"r\", stdin);\r\n\t\r\n\tscanf(\"%d%d%d%d%d\", &#038;n, &#038;m, &#038;t, &#038;a, &#038;b); mm = 2*m;\r\n\tfor (int i=0;i<m;i++){\r\n\t\tscanf(\"%d%d\", &#038;x, &#038;y);\r\n\t\tE[2*i].x = x, E[2*i].y = y;\r\n\t\tE[2*i+1].x = y, E[2*i+1].y = x;\r\n\t}\r\n\t\r\n\t\r\n\tfor (int i=0;i<mm;i++){\r\n\t\tfor (int j=0;j<mm;j++){\r\n\t\t\tif (i==j || (i^1)==j) continue;\r\n\t\t\tif (E[i].y == E[j].x) A.d[i][j] = 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tC = pow(A, t-1);\r\n\t\r\n\tfor (int i=0;i<mm;i++){\r\n\t\tif (E[i].x != a) continue;\r\n\t\tfor (int j=0;j<mm;j++)\r\n\t\t\tif (E[j].y == b) ans = (ans + C.d[i][j]) % _P;\r\n\t}\r\n\t\r\n\tprintf(\"%d\\n\", ans);\r\n}\r\n<\/pre>\n<p><bk><bk><bk><bk><br \/>\n<bk><bk><bk><bk><\/p>\n<h3>External link :<\/h3>\n<p><a href=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1875\">http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1875<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u7ed9\u5b9a\u4e00\u4e2a\u53ef\u80fd\u91cd\u8fb9\u4f46\u6ca1\u6709\u81ea\u73af\u7684\u65e0\u5411\u56fe\uff0c\u8981\u6c42\u8ba1\u7b97 A, B \u4e24\u70b9\u4e4b\u95f4\u6b65\u6570\u4e3a t \u7684\u65b9\u6848\u6570\u3002\u7b54\u6848\u6a21 45989\u3002 \uff08\u53ef\u4ee5\u7ecf\u8fc7\u67d0\u4e2a\u70b9\u67d0\u6761\u8fb9\u591a\u6b21\uff0c\u4f46\u662f\u4e0d\u53ef\u4ee5\u7acb\u5373\u6cbf\u7740\u540c\u4e00\u6761\u8fb9\u6298\u8fd4\u3002\uff09 \uff08.. N<\/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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-1a","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/72","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=72"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}