{"id":266,"date":"2012-11-15T10:51:00","date_gmt":"2012-11-15T02:51:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/171"},"modified":"2012-11-15T10:51:00","modified_gmt":"2012-11-15T02:51:00","slug":"poj_2185_tiled_matrix","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=266","title":{"rendered":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09"},"content":{"rendered":"<table border=\"0\" width=\"100%\" background=\"http:\/\/poj.org\/images\/table_back.jpg\" style=\"font-family:Simsun\">\n<tbody>\n<tr>\n<td>\n<div style=\"position:absolute; right:10px\">Language:<select size=\"1\"><option value=\"default\" selected=\"selected\"><br \/>\nDefault<\/option><\/select><\/div>\n<div class=\"ptt\" lang=\"en-US\" style=\"text-align:center; font-size:18pt; font-weight:bold; color:blue\">\nMilking Grid<\/div>\n<div class=\"plm\" style=\"text-align:center; font-size:12pt\">\n<table align=\"center\">\n<tbody>\n<tr>\n<td><strong>Time Limit:<\/strong>&nbsp;3000MS<\/td>\n<td width=\"10px\">&nbsp;<\/td>\n<td><strong>Memory Limit:<\/strong>&nbsp;65536K<\/td>\n<\/tr>\n<tr>\n<td><strong>Total Submissions:<\/strong>&nbsp;4346<\/td>\n<td width=\"10px\">&nbsp;<\/td>\n<td><strong>Accepted:<\/strong>&nbsp;1780<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Description<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u7ed9\u5b9aR<span style=\"font-family:'Times New Roman',Times,serif; font-size:16px\">(1 &lt;= R &lt;= 10,000)&nbsp;<\/span>*C<span style=\"font-family:'Times New Roman',Times,serif; font-size:16px\">&nbsp;(1 &lt;= C &lt;= 75)&nbsp;<\/span>\u7684\u77e9\u9635\uff0c\u6c42\u5b83\u7684\u6700\u5927\u5e73\u94fa\u77e9\u9635,\u4e0d\u591f\u7684\u5730\u65b9\u53ef\u90e8\u5206\u5e73\u94fa\uff0c\u4f46\u4e0d\u53ef\u91cd\u53e0\u3002<\/div>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Input<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u7b2c\u4e00\u884c\uff1aR\u548cC.<\/div>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u7b2c2-R&#43;1\u884c\u6bcf\u884cC\u4e2a\u5927\u5199\u5b57\u6bcd\uff0c\u8868\u793a\u77e9\u9635.<\/div>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Output<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u6700\u5927\u7684\u5e73\u94fa\u77e9\u9635\u9762\u79ef\n<\/div>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Sample Input<\/p>\n<pre class=\"sio\" style=\"font-family:'Courier New',Courier,monospace; font-size:12pt\">2 5\nABABA\nABABA\n<\/pre>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Sample Output<\/p>\n<pre class=\"sio\" style=\"font-family:'Courier New',Courier,monospace; font-size:12pt\">2\n<\/pre>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Hint<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\nThe entire milking grid can be constructed from repetitions of the pattern 'AB'.<\/div>\n<p class=\"pst\" style=\"font-size:18pt; font-weight:bold; color:blue\">Source<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n<a href=\"http:\/\/poj.org\/searchproblem?field=source&amp;key=USACO+2003+Fall\" style=\"text-decoration:none\">USACO 2003 Fall<\/a><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u663e\u7136\u8fd9\u4e2a\u77e9\u9635\u5fc5\u7136\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u7531\u4e8eC\u6bd4\u8f83\u5c11\uff0c\u5148\u627e\u51fa\u6bcf\u5217\u6700\u5927\u7684\u5e73\u94fa\u7ebf\u6bb5\uff08\u884c\u884c\u4e0d\u5f71\u54cd\uff09<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u518d\u8003\u8651\u6bcf\u884c\u5171\u6709\u4e14\u6700\u5c0f\u7684\u91cd\u590d\u90e8\u5206\uff08\u53ef\u4ee5\u8bc1\u660e\u589e\u52a0\u91cd\u590d\u90e8\u5206\u5bf9\u884c\u7684\u5927\u5c0f\u65e0\u5f71\u54cd\uff09<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u5728\u8003\u8651\u884cR\u226410000\uff0c\u5fc5\u987b\u7528Kmp\uff0c\u4e0d\u51e1\u5047\u8bbe\u53e5\u672b\u6709\u82e5\u5e72'????'<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u5219\u5bf9\u4e8e\u5b57\u7b26\u4e32\u7684P<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">AEICCCAEICCCAEI C &nbsp;C &nbsp;? &nbsp; ? &nbsp; ? &nbsp;...<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">000000123456789 10 11 12 &nbsp;13 &nbsp;14 ...<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u663e\u7136\uff1f\u540e\u7684P\u9012\u589e&#43;1\uff0c\u53c8\u56e0\u7b54\u6848\u4e3aMax\uff08i-p[i])\uff08i\u2265n\uff09<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u6240\u4ee5(n-p[n])=<span style=\"font-family:Simsun; font-size:14px\">Max\uff08i-p[i])<\/span><\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><span style=\"font-family:Simsun; font-size:14px\"><\/span><\/span><\/p>\n<pre name=\"code\" class=\"delphi\">Program grid;\nconst\n   maxn=10000;\n   maxm=75;\nvar\n   n,m,i,j,k:longint;\n   a:array[1..maxn] of string;\n   f:array[1..maxm] of longint;\n   flag:boolean;\n   p:array[1..maxn] of longint;\nbegin\n   fillchar(f,sizeof(f),0);\n   readln(n,m);\n   for i:=1 to n do\n   begin\n      readln(a[i]);\n      for j:=1 to m do\n      begin\n         flag:=true;\n         for k:=j+1 to m do\n            if a[i][k]&lt;&gt;a[i][k-j] then begin flag:=false; break; end;\n            if flag then inc(f[j]);\n      end;\n   end;\n   for i:=1 to m do if f[i]=n then break;\n   m:=i;\n\n   for i:=1 to n do delete(a[i],m+1,maxlongint);\n\n   j:=0;p[1]:=0;\n   for i:=2 to n do\n   begin\n      while (j&gt;0) and (a[i]&lt;&gt;a[j+1]) do j:=p[j];\n      if (a[i]=a[j+1]) then inc(j);\n      p[i]:=j;\n   end;\n\n   n:=n-p[n];\n   writeln(m*n);\n\n\n\n\n\nend.\n<\/pre>\n<\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Language: Default Milking Grid Time Limit:&nbsp;3000MS  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[34],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-kmp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=266\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good\" \/>\n<meta property=\"og:description\" content=\"Language: Default Milking Grid Time Limit:&nbsp;3000MS [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=266\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-15T02:51:00+00:00\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09\",\"datePublished\":\"2012-11-15T02:51:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266\"},\"wordCount\":84,\"commentCount\":0,\"keywords\":[\"KMP\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=266#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=266\",\"name\":\"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"datePublished\":\"2012-11-15T02:51:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=266\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=266#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=266","og_locale":"zh_CN","og_type":"article","og_title":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good","og_description":"Language: Default Milking Grid Time Limit:&nbsp;3000MS [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=266","og_site_name":"nike0good","article_published_time":"2012-11-15T02:51:00+00:00","author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=266#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=266"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09","datePublished":"2012-11-15T02:51:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=266"},"wordCount":84,"commentCount":0,"keywords":["KMP"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=266#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=266","url":"https:\/\/nike0good.com\/?p=266","name":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09 - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"datePublished":"2012-11-15T02:51:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=266#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=266"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=266#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"POJ 2185(\u6700\u5927\u5e73\u94fa\u77e9\u9635\uff09"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}